diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-08-09 11:47:56 +0000 |
|---|---|---|
| committer | Javiertxo <jtx@jtx.marker.es> | 2013-08-09 11:47:56 +0000 |
| commit | 4e358f420a7a1512c722d9eccd864416bc4c075b (patch) | |
| tree | 223e826158e09ab2c864abf0214fe1e6a714ab61 /src/unicoderange.cpp | |
| parent | Update to trunk (diff) | |
| parent | Remove missing files from POTFILES.in (diff) | |
| download | inkscape-4e358f420a7a1512c722d9eccd864416bc4c075b.tar.gz inkscape-4e358f420a7a1512c722d9eccd864416bc4c075b.zip | |
update to trunk
(bzr r11950.1.127)
Diffstat (limited to 'src/unicoderange.cpp')
| -rw-r--r-- | src/unicoderange.cpp | 192 |
1 files changed, 96 insertions, 96 deletions
diff --git a/src/unicoderange.cpp b/src/unicoderange.cpp index 67239d0d2..803e1a884 100644 --- a/src/unicoderange.cpp +++ b/src/unicoderange.cpp @@ -4,124 +4,124 @@ #include <string.h> static unsigned int hex2int(char* s){ - int res=0; - int i=0, mul=1; - while(s[i+1]!='\0') i++; + int res=0; + int i=0, mul=1; + while(s[i+1]!='\0') i++; - while(i>=0){ - if (s[i] >= 'A' && s[i] <= 'F') res += mul * (s[i]-'A'+10); - if (s[i] >= 'a' && s[i] <= 'f') res += mul * (s[i]-'a'+10); - if (s[i] >= '0' && s[i] <= '9') res += mul * (s[i]-'0'); - i--; - mul*=16; - } - return res; + while(i>=0){ + if (s[i] >= 'A' && s[i] <= 'F') res += mul * (s[i]-'A'+10); + if (s[i] >= 'a' && s[i] <= 'f') res += mul * (s[i]-'a'+10); + if (s[i] >= '0' && s[i] <= '9') res += mul * (s[i]-'0'); + i--; + mul*=16; + } + return res; } UnicodeRange::UnicodeRange(const gchar* value){ - if (!value) return; - gchar* val = (gchar*) value; - while(val[0] != '\0'){ - if (val[0]=='U' && val[1]=='+'){ - val += add_range(val+2); - } else { - this->unichars.push_back(g_utf8_get_char(&val[0])); - val++; - } - //skip spaces or commas - while(val[0]==' ' || val[0]==',') val++; - } + if (!value) return; + gchar* val = (gchar*) value; + while(val[0] != '\0'){ + if (val[0]=='U' && val[1]=='+'){ + val += add_range(val+2); + } else { + this->unichars.push_back(g_utf8_get_char(&val[0])); + val++; + } + //skip spaces or commas + while(val[0]==' ' || val[0]==',') val++; + } } -int -UnicodeRange::add_range(gchar* val){ - Urange r; - int i=0, count=0; - while(val[i]!='\0' && val[i]!='-' && val[i]!=' ' && val[i]!=','){ +int UnicodeRange::add_range(gchar* val){ + Urange r; + int i=0, count=0; + while(val[i]!='\0' && val[i]!='-' && val[i]!=' ' && val[i]!=','){ i++; - } + } r.start = (gchar*) malloc((i+1)*sizeof(gchar*)); - strncpy(r.start, val, i); - r.start[i] = '\0'; - val+=i; - count+=i; - i=0; - if (val[0]=='-'){ - val++; - while(val[i]!='\0' && val[i]!='-' && val[i]!=' ' && val[i]!=',') i++; - r.end = (gchar*) malloc((i+1)*sizeof(gchar*)); - strncpy(r.end, val, i); - r.end[i] = '\0'; - // val+=i; - count+=i; - } else { - r.end=NULL; - } - this->range.push_back(r); - return count+1; + strncpy(r.start, val, i); + r.start[i] = '\0'; + val+=i; + count+=i; + i=0; + if (val[0]=='-'){ + val++; + while(val[i]!='\0' && val[i]!='-' && val[i]!=' ' && val[i]!=',') i++; + r.end = (gchar*) malloc((i+1)*sizeof(gchar*)); + strncpy(r.end, val, i); + r.end[i] = '\0'; + // val+=i; + count+=i; + } else { + r.end=NULL; + } + this->range.push_back(r); + return count+1; } bool UnicodeRange::contains(gchar unicode){ - for(unsigned int i=0;i<this->unichars.size();i++){ - if ((gunichar) unicode == this->unichars[i]) return true; - } + for(unsigned int i=0;i<this->unichars.size();i++){ + if (static_cast<gunichar>(unicode) == this->unichars[i]){ + return true; + } + } - unsigned int unival; - unival = g_utf8_get_char (&unicode); - char uni[9] = "00000000"; - uni[8]= '\0'; - unsigned char val; - for (unsigned int i=7; unival>0; i--){ - val = unival & 0xf; - unival = unival >> 4; - if (val < 10) uni[i] = '0' + val; - else uni[i] = 'A'+ val - 10; - } + unsigned int unival; + unival = g_utf8_get_char (&unicode); + char uni[9] = "00000000"; + uni[8]= '\0'; + for (unsigned int i=7; unival>0; i--){ + unsigned char val = unival & 0xf; + unival = unival >> 4; + if (val < 10) uni[i] = '0' + val; + else uni[i] = 'A'+ val - 10; + } - bool found; - for(unsigned int i=0;i<this->range.size();i++){ - Urange r = this->range[i]; - if (r.end){ - if (unival >= hex2int(r.start) && unival <= hex2int(r.end)) return true; - } else { - found = true; + bool found; + for(unsigned int i=0;i<this->range.size();i++){ + Urange r = this->range[i]; + if (r.end){ + if (unival >= hex2int(r.start) && unival <= hex2int(r.end)) return true; + } else { + found = true; - int p=0; - while (r.start[p]!='\0') p++; - p--; + int p=0; + while (r.start[p]!='\0') p++; + p--; - for (int pos=8;p>=0;pos--,p--){ - if (uni[pos]!='?' && uni[pos]!=r.start[p]) found = false; - } - if (found) return true; - } - } - return false; + for (int pos=8;p>=0;pos--,p--){ + if (uni[pos]!='?' && uni[pos]!=r.start[p]) found = false; + } + if (found) return true; + } + } + return false; } Glib::ustring UnicodeRange::attribute_string(){ - Glib::ustring result; - unsigned int i; - for(i=0; i<this->unichars.size(); i++){ - result += this->unichars[i]; - if (i!=this->unichars.size()-1) result += ","; - } + Glib::ustring result; + unsigned int i; + for(i=0; i<this->unichars.size(); i++){ + result += this->unichars[i]; + if (i!=this->unichars.size()-1) result += ","; + } - for(i=0; i<this->range.size(); i++){ - result += "U+" + Glib::ustring(this->range[i].start); - if (this->range[i].end) result += "-" + Glib::ustring(this->range[i].end); - if (i!=this->range.size()-1) result += ", "; - } + for(i=0; i<this->range.size(); i++){ + result += "U+" + Glib::ustring(this->range[i].start); + if (this->range[i].end) result += "-" + Glib::ustring(this->range[i].end); + if (i!=this->range.size()-1) result += ", "; + } - return result; + return result; } gunichar UnicodeRange::sample_glyph(){ - //This could be better - if (!unichars.empty()) - return unichars[0]; - if (!range.empty()) - return hex2int(range[0].start); - return (gunichar) ' '; + //This could be better + if (!unichars.empty()) + return unichars[0]; + if (!range.empty()) + return hex2int(range[0].start); + return (gunichar) ' '; } |
