StringUtilities.h

00001 /*
00002  * This source file is part of libRocket, the HTML/CSS Interface Middleware
00003  *
00004  * For the latest information, see http://www.librocket.com
00005  *
00006  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy
00009  * of this software and associated documentation files (the "Software"), to deal
00010  * in the Software without restriction, including without limitation the rights
00011  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012  * copies of the Software, and to permit persons to whom the Software is
00013  * furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included in
00016  * all copies or substantial portions of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024  * THE SOFTWARE.
00025  *
00026  */
00027 
00028 #ifndef ROCKETCORESTRINGUTILITIES_H
00029 #define ROCKETCORESTRINGUTILITIES_H
00030 
00031 #include <Rocket/Core/Header.h>
00032 #include <Rocket/Core/Types.h>
00033 #include <Rocket/Core/String.h>
00034 #include <stdarg.h>
00035 
00036 namespace Rocket {
00037 namespace Core {
00038 
00044 class ROCKETCORE_API StringUtilities
00045 {
00046 public:
00052         static void ExpandString(StringList& string_list, const String& string, const char delimiter = ',');
00057         static void JoinString(String& string, const StringList& string_list, const char delimiter = ',');
00058 
00063         static String MD5Hash(const char* data, int length = -1);
00068         static Hash FNVHash(const char* data, int length = -1);
00069 
00075         static bool URLEncode(const char* input, size_t input_length, String& output);
00081         static bool URLDecode(const String& input, char* output, size_t output_length);
00082 
00088         static bool Base64Encode(const char* input, size_t input_length, String& output);
00094         static bool Base64Decode(const String& input, char* output, size_t output_length);
00095 
00101         static bool UTF8toUCS2(const String& input, std::vector< word >& output);
00107         static bool UCS2toUTF8(const std::vector< word >& input, String& output);
00114         static bool UCS2toUTF8(const word* input, size_t input_size, String& output);
00115 
00119         template < typename CharacterType >
00120         static bool IsWhitespace(CharacterType x)
00121         {
00122                 return (x == '\r' || x == '\n' || x == ' ' || x == '\t');
00123         }
00124 
00128         static String StripWhitespace(const String& string);
00129 
00130         struct ROCKETCORE_API ArgumentState
00131         {
00132                 ArgumentState();
00133 
00134                 int index;
00135                 char option;
00136                 const char* argument;
00137                 bool display_errors;
00138         };
00139 
00141         static int GetOpt(int nargc, char* nargv[], char* optstring, ArgumentState& arg_state);
00142 
00144         struct ROCKETCORE_API StringComparei
00145         {
00146                 bool operator()(const String& lhs, const String& rhs) const;
00147         };
00148 };
00149 
00150 }
00151 }
00152 
00153 #endif