VirtualBox

Changeset 17742 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Mar 12, 2009 1:12:10 PM (16 years ago)
Author:
vboxsync
Message:

Main: more string compare hacking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/string.h

    r17740 r17742  
    328328public:
    329329
     330    enum CaseSensitivity
     331    {
     332        CaseSensitive,
     333        CaseInsensitive
     334    };
     335
    330336    typedef char *String;
    331337    typedef const char *ConstString;
     
    438444    }
    439445
    440     int compare (const char *s) const
    441     {
    442         if (str == s)
     446    int compare (const char *pcsz, CaseSensitivity cs = CaseSensitive) const
     447    {
     448        if (str == pcsz)
    443449            return 0;
    444450        if (str == NULL)
    445451            return -1;
    446         if (s == NULL)
     452        if (pcsz == NULL)
    447453            return 1;
    448454
    449         return ::strcmp (str, s);
    450     }
    451 
    452     bool operator == (const Utf8Str &that) const { return !compare (that.str); }
    453     bool operator != (const Utf8Str &that) const { return !!compare (that.str); }
     455        if (cs == CaseSensitive)
     456            return ::RTStrCmp(str, pcsz);
     457        else
     458            return ::RTStrICmp(str, pcsz);
     459    }
     460
     461    int compare (const Utf8Str &that, CaseSensitivity cs = CaseSensitive) const
     462    {
     463        return compare (that.str, cs);
     464    }
     465
     466    bool operator == (const Utf8Str &that) const { return !compare (that); }
     467    bool operator != (const Utf8Str &that) const { return !!compare (that); }
    454468    bool operator == (const char *that) const { return !compare (that); }
    455469    bool operator != (const char *that) const { return !!compare (that); }
    456     bool operator < (const Utf8Str &that) const { return compare (that.str) < 0; }
     470    bool operator < (const Utf8Str &that) const { return compare (that) < 0; }
    457471    bool operator < (const char *that) const { return compare (that) < 0; }
    458472
    459     int compareIgnoreCase(const char *pcsz) const
    460     {
    461         return ::RTStrICmp(str, pcsz);
    462     }
    463 
    464     bool endsWith (const Utf8Str &that) const
     473    bool endsWith (const Utf8Str &that, CaseSensitivity cs = CaseSensitive) const
    465474    {
    466475        if (length() < that.length())
     
    468477
    469478        int l = length() - that.length();
    470         return ::strcmp (&str[l], that.str) == 0;
     479        if (cs == CaseSensitive)
     480            return ::RTStrCmp(&str[l], that.str) == 0;
     481        else
     482            return ::RTStrICmp(&str[l], that.str) == 0;
     483    }
     484
     485    bool startsWith (const Utf8Str &that, CaseSensitivity cs = CaseSensitive) const
     486    {
     487        if (length() < that.length())
     488            return false;
     489
     490        if (cs == CaseSensitive)
     491            return ::RTStrNCmp(str, that.str, that.length()) == 0;
     492        else
     493            return ::RTStrNICmp(str, that.str, that.length()) == 0;
    471494    }
    472495
Note: See TracChangeset for help on using the changeset viewer.

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