};
/**
-Base class for string codecs. Mostly abstract. Use one of the derived classes
-or the function create_codec to create a specific codec.
+Base class for string codecs. Use one of the derived classes or the function
+create_codec to create a specific codec.
For the purposes of this class, an std::wstring is considered to contain
Unicode characters and an std::string is considered to be an encoded sequence
-of bytes. Codecs are able to determine if an encoded string could be
+of bytes. A codec is able to determine if an encoded string could be decoded
+with it.
*/
class StringCodec
{
function to put the result into the internal buffer.
*/
virtual void encode_char(wchar_t) =0;
-
+
/**
Encodes a string.
*/
virtual void encode(const std::wstring &s)
{ for(std::wstring::const_iterator i=s.begin(); i!=s.end(); ++i) encode_char(*i); }
-
+
/**
Brings the encoder back to its initial state. This allows the encoded
sequence to be extracted or flushed without loss of integrity.
Returns the number of bytes in the output buffer.
*/
unsigned size() const { return buffer_.size(); }
-
+
/**
Clears the encoded sequence. Encoder state is left intact.
*/
};
/**
-Convenience function that decodes a string using the given codec.
+Convenience function that decodes a string using the given codec.
*/
template<class C>
std::wstring decode(const std::string &s)
{
if(escape)
{
- escape=escape<<8 | (unsigned char)*i;
+ escape=escape<<8 | static_cast<unsigned char>(*i);
if(*i>='@' && *i<='Z')
{
switch(escape)
{
if(i+bit>=ucs_to_jisx0208_table_size)
continue;
- if(ucs_to_jisx0208_table[i+bit].ucs<=(unsigned short)c)
+ if(ucs_to_jisx0208_table[i+bit].ucs<=static_cast<unsigned short>(c))
i+=bit;
}
- if(ucs_to_jisx0208_table[i].ucs==(unsigned short)c)
+ if(ucs_to_jisx0208_table[i].ucs==static_cast<unsigned short>(c))
return ucs_to_jisx0208_table[i].jis;
return 0;
}
{
if(i==str.end())
return;
- append((unsigned char)*i++);
+ append(static_cast<unsigned char>(*i++));
}
} // namespace Msp
*/
string tolower(const string &str)
{
- string result(str);
+ string result(str);
transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}
*/
string toupper(const string &str)
{
- string result(str);
+ string result(str);
transform(result.begin(), result.end(), result.begin(), ::toupper);
return result;
}
unsigned start=str.find_first_not_of(sep);
while(start<str.size())
{
- unsigned end=str.find_first_of(sep, start);
+ unsigned end=str.find_first_of(sep, start);
result.push_back(str.substr(start, end-start));
if(end==string::npos) break;
if(allow_empty)
vector<string> split(const string &str, char sep, bool allow_empty)
{
- return split(str, string(1,sep), allow_empty);
+ return split(str, string(1, sep), allow_empty);
}
/**