mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-29 18:59:14 +08:00
fix TextUtils::replace,Assets::getString
This commit is contained in:
parent
81700df12f
commit
f9f7bd8207
@ -42,7 +42,7 @@ class CDROIDHandler( xml.sax.ContentHandler ):
|
||||
if self.isMyNS(value):
|
||||
self.addID(value)
|
||||
if 'string/' in value:
|
||||
value = self.normalizeXMLString(value)
|
||||
#value = self.normalizeXMLString(value),this is done in cdroid Assets::getString
|
||||
self.addString(value)
|
||||
|
||||
def addID(self,name):
|
||||
|
@ -301,21 +301,20 @@ int Assets::getNextAutofillId(){
|
||||
return mNextAutofillViewId++;
|
||||
}
|
||||
|
||||
const std::string& Assets::getString(const std::string& resid,const std::string&lan) {
|
||||
const std::string Assets::getString(const std::string& resid,const std::string&lan) {
|
||||
if((!lan.empty())&&(mLanguage!=lan)) {
|
||||
loadStrings(lan);
|
||||
}
|
||||
std::string str = resid;
|
||||
std::string pkg,name=resid;
|
||||
parseResource(resid,&name,&pkg);
|
||||
name = AttributeSet::normalize(pkg,resid);
|
||||
auto itr = mStrings.find(name);
|
||||
if(itr != mStrings.end()) {
|
||||
std::string str=itr->second;
|
||||
TextUtils::replace("\\n","\n");
|
||||
TextUtils::replace("\\r","\r");
|
||||
return str;
|
||||
str = itr->second;
|
||||
}
|
||||
return resid;
|
||||
TextUtils::replace(str,"\\n","\n");
|
||||
return str;
|
||||
}
|
||||
|
||||
int Assets::getArray(const std::string&resid,std::vector<int>&out) {
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
const DisplayMetrics&getDisplayMetrics()const override;
|
||||
int getId(const std::string&)const override;
|
||||
int getNextAutofillId()override;
|
||||
const std::string& getString(const std::string&id,const std::string&lan="")override;
|
||||
const std::string getString(const std::string&id,const std::string&lan="")override;
|
||||
Cairo::RefPtr<Cairo::ImageSurface> getImage(const std::string&resname)override;
|
||||
std::vector<std::string> getStringArray(const std::string&resname,const std::string&arrayname)const;
|
||||
std::unique_ptr<std::istream> getInputStream(const std::string&resname,std::string*outpkg=nullptr)override;
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
virtual const DisplayMetrics&getDisplayMetrics()const=0;
|
||||
virtual int getId(const std::string&)const=0;
|
||||
virtual int getNextAutofillId()=0;
|
||||
virtual const std::string& getString(const std::string&id,const std::string&lan="")=0;
|
||||
virtual const std::string getString(const std::string&id,const std::string&lan="")=0;
|
||||
static Cairo::RefPtr<Cairo::ImageSurface> loadImage( std::istream&istream ){
|
||||
return Cairo::ImageSurface::create_from_stream(istream);
|
||||
}
|
||||
|
@ -137,14 +137,14 @@ std::string& TextUtils::trim(std::string&s){
|
||||
return s;
|
||||
}
|
||||
|
||||
int TextUtils::replace(std::string&str,const std::string&sfind,const std::string&sreplace){
|
||||
size_t pos;
|
||||
int count=0;
|
||||
while((pos=str.find_first_of(sfind))!=std::string::npos){
|
||||
str.replace(pos,pos+sfind.length(),sreplace);
|
||||
count++;
|
||||
std::string& TextUtils::replace(std::string&src,const std::string&old_value,const std::string&new_value){
|
||||
for (std::string::size_type pos(0); pos != std::string::npos; pos += new_value.length()) {
|
||||
if ((pos = src.find(old_value, pos)) != std::string::npos) {
|
||||
src.replace(pos, old_value.length(), new_value);
|
||||
}
|
||||
else break;
|
||||
}
|
||||
return count;
|
||||
return src;
|
||||
}
|
||||
|
||||
long TextUtils::strtol(const std::string&value){
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
static bool startWith(const std::string&str,const std::string&head);
|
||||
static bool endWith(const std::string&str,const std::string&tail);
|
||||
static std::string& trim(std::string&);
|
||||
static int replace(std::string&str,const std::string&sfind,const std::string&sreplace);
|
||||
static std::string& replace(std::string&str,const std::string&sfind,const std::string&sreplace);
|
||||
static long strtol(const std::string&value);
|
||||
static std::vector<std::string> split(const std::string& s,const std::string& delim);
|
||||
static int UCS2UTF(wchar_t wc,char*oututf,int outlen);
|
||||
|
@ -366,14 +366,9 @@ void TextAppearanceAttributes::readTextAppearance(Context*ctx,const AttributeSet
|
||||
TextView::TextView(Context*ctx,const AttributeSet& attrs)
|
||||
:View(ctx,attrs){
|
||||
initView();
|
||||
std::string text = ctx->getString(attrs.getString("text"));
|
||||
TextUtils::replace(text,"\\n","\n");
|
||||
TextUtils::replace(text,"\\r","\r");
|
||||
setText(text);
|
||||
text = ctx->getString(attrs.getString("hint"));
|
||||
TextUtils::replace(text,"\\n","\n");
|
||||
TextUtils::replace(text,"\\r","\r");
|
||||
setHint(text);
|
||||
|
||||
setText(ctx->getString(attrs.getString("text")));
|
||||
setHint(ctx->getString(attrs.getString("hint")));
|
||||
|
||||
Drawable* left = attrs.getDrawable("drawableLeft");
|
||||
Drawable*right = attrs.getDrawable("drawableRight");
|
||||
|
Loading…
Reference in New Issue
Block a user