See http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp615 for the full rules.
| 97 | |
| 98 | // See http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp615 for the full rules. |
| 99 | std::string MangleForJni(const std::string& s) { |
| 100 | std::string result; |
| 101 | size_t char_count = CountModifiedUtf8Chars(s.c_str()); |
| 102 | const char* cp = &s[0]; |
| 103 | for (size_t i = 0; i < char_count; ++i) { |
| 104 | uint32_t ch = GetUtf16FromUtf8(&cp); |
| 105 | if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) { |
| 106 | result.push_back(ch); |
| 107 | } else if (ch == '.' || ch == '/') { |
| 108 | result += "_"; |
| 109 | } else if (ch == '_') { |
| 110 | result += "_1"; |
| 111 | } else if (ch == ';') { |
| 112 | result += "_2"; |
| 113 | } else if (ch == '[') { |
| 114 | result += "_3"; |
| 115 | } else { |
| 116 | const uint16_t leading = GetLeadingUtf16Char(ch); |
| 117 | const uint32_t trailing = GetTrailingUtf16Char(ch); |
| 118 | |
| 119 | StringAppendF(&result, "_0%04x", leading); |
| 120 | if (trailing != 0) { |
| 121 | StringAppendF(&result, "_0%04x", trailing); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | return result; |
| 126 | } |
| 127 | |
| 128 | std::string DotToDescriptor(const char* class_name) { |
| 129 | std::string descriptor(class_name); |
no test coverage detected