From: Scott Wheeler Date: Wed, 30 Jan 2008 12:42:23 +0000 (+0000) Subject: Add methods to check if this string is Latin1/ASCII compatible. X-Git-Tag: v1.5~53 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bdad22b3c693ffb94f91b443589917a34a19de62;p=taglib Add methods to check if this string is Latin1/ASCII compatible. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@768593 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 86f386db..79e1beea 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -461,6 +461,24 @@ String String::stripWhiteSpace() const return String(wstring(begin, end + 1)); } +bool String::isLatin1() const +{ + for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); it++) { + if(*it >= 256) + return false; + } + return true; +} + +bool String::isAscii() const +{ + for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); it++) { + if(*it >= 128) + return false; + } + return true; +} + String String::number(int n) // static { if(n == 0) diff --git a/taglib/toolkit/tstring.h b/taglib/toolkit/tstring.h index 1f990755..1abdd70e 100644 --- a/taglib/toolkit/tstring.h +++ b/taglib/toolkit/tstring.h @@ -292,6 +292,16 @@ namespace TagLib { */ String stripWhiteSpace() const; + /*! + * Returns true if the file only uses characters required by Latin1. + */ + bool isLatin1() const; + + /*! + * Returns true if the file only uses characters required by (7-bit) ASCII. + */ + bool isAscii() const; + /*! * Converts the base-10 integer \a n to a string. */