Changeset 21588 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Jul 14, 2009 4:22:06 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 50084
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/string.cpp
r21529 r21588 37 37 const Utf8Str Utf8Str::Null; /* default ctor is OK */ 38 38 39 const size_t Utf8Str::npos = (size_t)-1;40 41 size_t Utf8Str::find(const char *pcszFind,42 size_t pos /*= 0*/)43 const44 {45 const char *pszThis, *p;46 47 if ( ((pszThis = c_str()))48 && (pos < length())49 && ((p = strstr(pszThis + pos, pcszFind)))50 )51 return p - pszThis;52 53 return npos;54 }55 56 Utf8Str Utf8Str::substr(size_t pos /*= 0*/, size_t n /*= npos*/)57 const58 {59 Utf8Str ret;60 61 if (n)62 {63 const char *psz;64 65 if ((psz = c_str()))66 {67 RTUNICP cp;68 69 // walk the UTF-8 characters until where the caller wants to start70 size_t i = pos;71 while (*psz && i--)72 if (RT_FAILURE(RTStrGetCpEx(&psz, &cp)))73 return ret; // return empty string on bad encoding74 75 const char *pFirst = psz;76 77 if (n == npos)78 // all the rest:79 ret = pFirst;80 else81 {82 i = n;83 while (*psz && i--)84 if (RT_FAILURE(RTStrGetCpEx(&psz, &cp)))85 return ret; // return empty string on bad encoding86 87 size_t cbCopy = psz - pFirst;88 ret.reserve(cbCopy + 1);89 memcpy(ret.m_psz, pFirst, cbCopy);90 ret.m_cbLength = cbCopy;91 ret.m_psz[cbCopy] = '\0';92 }93 }94 }95 96 return ret;97 }98 99 bool Utf8Str::endsWith(const Utf8Str &that, CaseSensitivity cs /*= CaseSensitive*/) const100 {101 size_t l1 = length();102 if (l1 == 0)103 return false;104 105 size_t l2 = that.length();106 if (l1 < l2)107 return false;108 109 size_t l = l1 - l2;110 if (cs == CaseSensitive)111 return ::RTStrCmp(&m_psz[l], that.m_psz) == 0;112 else113 return ::RTStrICmp(&m_psz[l], that.m_psz) == 0;114 }115 116 bool Utf8Str::startsWith(const Utf8Str &that, CaseSensitivity cs /*= CaseSensitive*/) const117 {118 size_t l1 = length();119 size_t l2 = that.length();120 if (l1 == 0 || l2 == 0)121 return false;122 123 if (l1 < l2)124 return false;125 126 if (cs == CaseSensitive)127 return ::RTStrNCmp(m_psz, that.m_psz, l2) == 0;128 else129 return ::RTStrNICmp(m_psz, that.m_psz, l2) == 0;130 }131 132 bool Utf8Str::contains(const Utf8Str &that, CaseSensitivity cs /*= CaseSensitive*/) const133 {134 if (cs == CaseSensitive)135 return ::RTStrStr(m_psz, that.m_psz) != NULL;136 else137 return ::RTStrIStr(m_psz, that.m_psz) != NULL;138 }139 140 39 Utf8Str& Utf8Str::toLower() 141 40 { … … 168 67 RTPathStripExt(m_psz); 169 68 jolt(); 170 }171 172 int Utf8Str::toInt(uint64_t &i) const173 {174 if (!m_psz)175 return VERR_NO_DIGITS;176 return RTStrToUInt64Ex(m_psz, NULL, 0, &i);177 }178 179 int Utf8Str::toInt(uint32_t &i) const180 {181 if (!m_psz)182 return VERR_NO_DIGITS;183 return RTStrToUInt32Ex(m_psz, NULL, 0, &i);184 69 } 185 70
Note:
See TracChangeset
for help on using the changeset viewer.