예제 #1
0
LString LString::fromUtf8(const std::string &s) {
    if (s.size() == 0) return LString();
    const uint8_t *begin = reinterpret_cast<const uint8_t*>(s.c_str());
    const uint8_t *end = begin + s.size();
    LString ret;
    ret.reserve(s.size());

    LChar *destBegin = ret.begin();
    LChar *destEnd = ret.end();
    bool conversionSucceeded = utf8ToUtf32(&begin, end, &destBegin, destEnd);
    assert(conversionSucceeded && "Failed conversion utf8 -> utf32");

    ret.resize(destBegin - ret.begin());
    return ret;
}
static char utf8ToU8GlibFontEncoding(const char *str)
{
  size_t i;
  uint32_t utf32Char;
  U8GettextCharMapping charMapping;

  utf32Char = utf8ToUtf32(str);

  // Slowest way to translate string to U8Glib font encoding
  for(i = 0; i < *sContext->charMappingCount; ++ i) {
    memcpy_P(&charMapping, sContext->charMappings + i, sizeof(charMapping));
    if (charMapping.utf32Char == utf32Char) {
      return charMapping.u8gChar;
    }
  }

  return '\0';
}