Home | History | Annotate | Download | only in host
      1 #include <host/pseudolocalize.h>
      2 
      3 using namespace std;
      4 
      5 static const char*
      6 pseudolocalize_char(char c)
      7 {
      8     switch (c) {
      9         case 'a':   return "\xc4\x83";
     10         case 'b':   return "\xcf\x84";
     11         case 'c':   return "\xc4\x8b";
     12         case 'd':   return "\xc4\x8f";
     13         case 'e':   return "\xc4\x99";
     14         case 'f':   return "\xc6\x92";
     15         case 'g':   return "\xc4\x9d";
     16         case 'h':   return "\xd1\x9b";
     17         case 'i':   return "\xcf\x8a";
     18         case 'j':   return "\xc4\xb5";
     19         case 'k':   return "\xc4\xb8";
     20         case 'l':   return "\xc4\xba";
     21         case 'm':   return "\xe1\xb8\xbf";
     22         case 'n':   return "\xd0\xb8";
     23         case 'o':   return "\xcf\x8c";
     24         case 'p':   return "\xcf\x81";
     25         case 'q':   return "\x51";
     26         case 'r':   return "\xd2\x91";
     27         case 's':   return "\xc5\xa1";
     28         case 't':   return "\xd1\x82";
     29         case 'u':   return "\xce\xb0";
     30         case 'v':   return "\x56";
     31         case 'w':   return "\xe1\xba\x85";
     32         case 'x':   return "\xd1\x85";
     33         case 'y':   return "\xe1\xbb\xb3";
     34         case 'z':   return "\xc5\xba";
     35         case 'A':   return "\xc3\x85";
     36         case 'B':   return "\xce\xb2";
     37         case 'C':   return "\xc4\x88";
     38         case 'D':   return "\xc4\x90";
     39         case 'E':   return "\xd0\x84";
     40         case 'F':   return "\xce\x93";
     41         case 'G':   return "\xc4\x9e";
     42         case 'H':   return "\xc4\xa6";
     43         case 'I':   return "\xd0\x87";
     44         case 'J':   return "\xc4\xb5";
     45         case 'K':   return "\xc4\xb6";
     46         case 'L':   return "\xc5\x81";
     47         case 'M':   return "\xe1\xb8\xbe";
     48         case 'N':   return "\xc5\x83";
     49         case 'O':   return "\xce\x98";
     50         case 'P':   return "\xcf\x81";
     51         case 'Q':   return "\x71";
     52         case 'R':   return "\xd0\xaf";
     53         case 'S':   return "\xc8\x98";
     54         case 'T':   return "\xc5\xa6";
     55         case 'U':   return "\xc5\xa8";
     56         case 'V':   return "\xce\xbd";
     57         case 'W':   return "\xe1\xba\x84";
     58         case 'X':   return "\xc3\x97";
     59         case 'Y':   return "\xc2\xa5";
     60         case 'Z':   return "\xc5\xbd";
     61         default:    return NULL;
     62     }
     63 }
     64 
     65 /**
     66  * Converts characters so they look like they've been localized.
     67  *
     68  * Note: This leaves escape sequences untouched so they can later be
     69  * processed by ResTable::collectString in the normal way.
     70  */
     71 string
     72 pseudolocalize_string(const string& source)
     73 {
     74     const char* s = source.c_str();
     75     string result;
     76     const size_t I = source.length();
     77     for (size_t i=0; i<I; i++) {
     78         char c = s[i];
     79         if (c == '\\') {
     80             if (i<I-1) {
     81                 result += '\\';
     82                 i++;
     83                 c = s[i];
     84                 switch (c) {
     85                     case 'u':
     86                         // this one takes up 5 chars
     87                         result += string(s+i, 5);
     88                         i += 4;
     89                         break;
     90                     case 't':
     91                     case 'n':
     92                     case '#':
     93                     case '@':
     94                     case '?':
     95                     case '"':
     96                     case '\'':
     97                     case '\\':
     98                     default:
     99                         result += c;
    100                         break;
    101                 }
    102             } else {
    103                 result += c;
    104             }
    105         } else {
    106             const char* p = pseudolocalize_char(c);
    107             if (p != NULL) {
    108                 result += p;
    109             } else {
    110                 result += c;
    111             }
    112         }
    113     }
    114 
    115     //printf("result=\'%s\'\n", result.c_str());
    116     return result;
    117 }
    118 
    119 
    120