string_help.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2009 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00031 
00032 #pragma once
00033 
00034 #include "../api_core.h"
00035 #include "string_types.h"
00036 #include <vector>
00037 
00038 #ifdef __cplusplus_cli
00039 #pragma managed(push, on)
00040 #include <vcclr.h>
00041 #endif
00042 
00046 class CL_API_CORE CL_StringHelp
00047 {
00050 
00051 public:
00052         static std::vector<CL_TempString> split_text(
00053                 const CL_StringRef &text,
00054                 const CL_StringRef &split_string,
00055                 bool skip_empty = true);
00056 
00062         static CL_TempString trim(const CL_StringRef &text);
00063 
00071         static int compare(const CL_StringRef8 &a, const CL_StringRef8 &b, bool case_insensitive = false);
00072 
00080         static int compare(const CL_StringRef16 &a, const CL_StringRef16 &b, bool case_insensitive = false);
00081 
00087         static CL_TempString text_to_upper(const CL_StringRef &s);
00088 
00094         static CL_TempString8 local8_to_upper(const CL_StringRef8 &s);
00095 
00101         static CL_TempString16 ucs2_to_upper(const CL_StringRef16 &s);
00102 
00108         static CL_TempString text_to_lower(const CL_StringRef &s);
00109 
00115         static CL_TempString8 local8_to_lower(const CL_StringRef8 &s);
00116 
00122         static CL_TempString16 ucs2_to_lower(const CL_StringRef16 &s);
00123 
00130         static CL_TempString float_to_text(float value, int num_decimal_places=6);
00131 
00138         static CL_TempString8 float_to_local8(float value, int num_decimal_places=6);
00139 
00146         static CL_TempString16 float_to_ucs2(float value, int num_decimal_places=6);
00147 
00153         static float text_to_float(const CL_StringRef &value);
00154 
00160         static float local8_to_float(const CL_StringRef8 &value);
00161 
00167         static float ucs2_to_float(const CL_StringRef16 &value);
00168 
00175         static CL_TempString double_to_text(double value, int num_decimal_places=6);
00176 
00183         static CL_TempString8 double_to_local8(double value, int num_decimal_places=6);
00184 
00191         static CL_TempString16 double_to_ucs2(double value, int num_decimal_places=6);
00192 
00198         static double text_to_double(const CL_StringRef &value);
00199 
00205         static double local8_to_double(const CL_StringRef8 &value);
00206 
00212         static double ucs2_to_double(const CL_StringRef16 &value);
00213 
00219         static CL_TempString int_to_text(int value);
00220 
00226         static CL_TempString8 int_to_local8(int value);
00227 
00233         static CL_TempString16 int_to_ucs2(int value);
00234 
00241         static int text_to_int(const CL_StringRef &value, int base = 10);
00242 
00249         static int local8_to_int(const CL_StringRef8 &value, int base = 10);
00250 
00257         static int ucs2_to_int(const CL_StringRef16 &value, int base = 10);
00258 
00264         static CL_TempString uint_to_text(unsigned int value);
00265 
00271         static CL_TempString8 uint_to_local8(unsigned int value);
00272 
00278         static CL_TempString16 uint_to_ucs2(unsigned int value);
00279 
00280         static unsigned int text_to_uint(const CL_StringRef &value, int base = 10);
00281 
00282         static unsigned int local8_to_uint(const CL_StringRef8 &value, int base = 10);
00283 
00284         static unsigned int ucs2_to_uint(const CL_StringRef16 &value, int base = 10);
00285 
00291         static CL_TempString bool_to_text(bool value);
00292 
00298         static CL_TempString8 bool_to_local8(bool value);
00299 
00305         static CL_TempString16 bool_to_ucs2(bool value);
00306 
00312         static bool text_to_bool(const CL_StringRef &value);
00313 
00319         static bool local8_to_bool(const CL_StringRef8 &value);
00320 
00326         static bool ucs2_to_bool(const CL_StringRef16 &value);
00327 
00333         static CL_TempString8 text_to_cp437(const CL_StringRef &text);
00334 
00340         static CL_TempString8 ucs2_to_cp437(const CL_StringRef16 &text);
00341 
00347         static CL_TempString cp437_to_text(const CL_StringRef8 &cp437);
00348 
00354         static CL_TempString16 cp437_to_ucs2(const CL_StringRef8 &cp437);
00355 
00361         static CL_TempString8 text_to_local8(const CL_StringRef &text);
00362 
00368         static CL_TempString8 text_to_utf8(const CL_StringRef &text);
00369 
00375         static CL_TempString8 ucs2_to_latin1(const CL_StringRef16 &ucs2);
00376 
00382         static CL_TempString8 ucs2_to_latin9(const CL_StringRef16 &ucs2);
00383 
00389         static CL_TempString8 ucs2_to_local8(const CL_StringRef16 &ucs2);
00390 
00396         static CL_TempString8 ucs2_to_utf8(const CL_StringRef16 &ucs2);
00397 
00403         static CL_TempString local8_to_text(const CL_StringRef8 &local8);
00404 
00410         static CL_TempString ucs2_to_text(const CL_StringRef16 &ucs2);
00411 
00417         static CL_TempString16 latin1_to_ucs2(const CL_StringRef8 &latin1);
00418 
00424         static CL_TempString16 latin9_to_ucs2(const CL_StringRef8 &latin9);
00425 
00431         static CL_TempString16 local8_to_ucs2(const CL_StringRef8 &local8);
00432 
00438         static CL_TempString16 utf8_to_ucs2(const CL_StringRef8 &utf8);
00439 
00445         static CL_TempString utf8_to_text(const CL_StringRef8 &utf8);
00446 
00447         enum BOMType
00448         {
00449                 bom_none,
00450                 bom_utf32_be,
00451                 bom_utf32_le,
00452                 bom_utf16_be,
00453                 bom_utf16_le,
00454                 bom_utf8
00455         };
00456 
00463         static BOMType detect_bom(const void *data, CL_String::size_type length);
00464 
00465 #ifdef __cplusplus_cli
00466 #ifdef UNICODE
00467 
00473         static CL_TempString clr_to_text(const System::String ^str)
00474         {
00475                 return clr_to_ucs2(str);
00476         }
00477 
00478         static System::String ^text_to_clr(const CL_StringRef &str)
00479         {
00480                 return ucs2_to_clr(str);
00481         }
00482 #else
00483 
00489         static CL_TempString clr_to_text(const System::String ^str)
00490         {
00491                 return ucs2_to_text(clr_to_ucs2(str));
00492         }
00493 
00494         static System::String ^text_to_clr(const CL_StringRef &str)
00495         {
00496                 return ucs2_to_clr(local8_to_ucs2(str));
00497         }
00498 #endif
00499 
00505         static CL_TempString16 clr_to_ucs2(const System::String ^str)
00506         {
00507                 cli::pin_ptr<const wchar_t> chars = PtrToStringChars(str);
00508                 return CL_TempString16(chars);
00509         }
00510 
00511         static System::String ^ucs2_to_clr(const CL_StringRef16 &str)
00512         {
00513                 return gcnew System::String(str.c_str());
00514         }
00515 #endif
00516 
00520 
00521 private:
00522         static const char trailing_bytes_for_utf8[256];
00523 
00524         static const unsigned char bitmask_leadbyte_for_utf8[6];
00526 };
00527 
00528 #ifdef __cplusplus_cli
00529 #pragma managed(pop)
00530 #endif
00531 

Generated on Thu Dec 3 02:39:32 2009 for ClanLib by  doxygen 1.4.6