VirtualBox

Changeset 21588 in vbox for trunk/src/VBox/Main/glue


Ignore:
Timestamp:
Jul 14, 2009 4:22:06 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
50084
Message:

Main: move vbox-independent OVF reader code to separate file; move some more string implementation from com::UTF8Str to iprt::MiniString

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/string.cpp

    r21529 r21588  
    3737const Utf8Str Utf8Str::Null; /* default ctor is OK */
    3838
    39 const size_t Utf8Str::npos = (size_t)-1;
    40 
    41 size_t Utf8Str::find(const char *pcszFind,
    42                      size_t pos /*= 0*/)
    43     const
    44 {
    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     const
    58 {
    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 start
    70             size_t i = pos;
    71             while (*psz && i--)
    72                 if (RT_FAILURE(RTStrGetCpEx(&psz, &cp)))
    73                     return ret;     // return empty string on bad encoding
    74 
    75             const char *pFirst = psz;
    76 
    77             if (n == npos)
    78                 // all the rest:
    79                 ret = pFirst;
    80             else
    81             {
    82                 i = n;
    83                 while (*psz && i--)
    84                     if (RT_FAILURE(RTStrGetCpEx(&psz, &cp)))
    85                         return ret;     // return empty string on bad encoding
    86 
    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*/) const
    100 {
    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     else
    113         return ::RTStrICmp(&m_psz[l], that.m_psz) == 0;
    114 }
    115 
    116 bool Utf8Str::startsWith(const Utf8Str &that, CaseSensitivity cs /*= CaseSensitive*/) const
    117 {
    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     else
    129         return ::RTStrNICmp(m_psz, that.m_psz, l2) == 0;
    130 }
    131 
    132 bool Utf8Str::contains(const Utf8Str &that, CaseSensitivity cs /*= CaseSensitive*/) const
    133 {
    134     if (cs == CaseSensitive)
    135         return ::RTStrStr(m_psz, that.m_psz) != NULL;
    136     else
    137         return ::RTStrIStr(m_psz, that.m_psz) != NULL;
    138 }
    139 
    14039Utf8Str& Utf8Str::toLower()
    14140{
     
    16867    RTPathStripExt(m_psz);
    16968    jolt();
    170 }
    171 
    172 int Utf8Str::toInt(uint64_t &i) const
    173 {
    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) const
    180 {
    181     if (!m_psz)
    182         return VERR_NO_DIGITS;
    183     return RTStrToUInt32Ex(m_psz, NULL, 0, &i);
    18469}
    18570
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette