Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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_String> split_text(
00053 const CL_StringRef &text,
00054 const CL_StringRef &split_string,
00055 bool skip_empty = true);
00056
00061 static CL_String8 wchar_to_utf8(wchar_t value);
00062
00067 static CL_String8 unicode_to_utf8(unsigned int value);
00068
00074 static CL_String trim(const CL_StringRef &text);
00075
00083 static int compare(const CL_StringRef8 &a, const CL_StringRef8 &b, bool case_insensitive = false);
00084
00092 static int compare(const CL_StringRef16 &a, const CL_StringRef16 &b, bool case_insensitive = false);
00093
00099 static CL_String text_to_upper(const CL_StringRef &s);
00100
00106 static CL_String8 local8_to_upper(const CL_StringRef8 &s);
00107
00113 static CL_String16 ucs2_to_upper(const CL_StringRef16 &s);
00114
00120 static CL_String text_to_lower(const CL_StringRef &s);
00121
00127 static CL_String8 local8_to_lower(const CL_StringRef8 &s);
00128
00134 static CL_String16 ucs2_to_lower(const CL_StringRef16 &s);
00135
00142 static CL_String float_to_text(float value, int num_decimal_places=6);
00143
00150 static CL_String8 float_to_local8(float value, int num_decimal_places=6);
00151
00158 static CL_String16 float_to_ucs2(float value, int num_decimal_places=6);
00159
00165 static float text_to_float(const CL_StringRef &value);
00166
00172 static float local8_to_float(const CL_StringRef8 &value);
00173
00179 static float ucs2_to_float(const CL_StringRef16 &value);
00180
00187 static CL_String double_to_text(double value, int num_decimal_places=6);
00188
00195 static CL_String8 double_to_local8(double value, int num_decimal_places=6);
00196
00203 static CL_String16 double_to_ucs2(double value, int num_decimal_places=6);
00204
00210 static double text_to_double(const CL_StringRef &value);
00211
00217 static double local8_to_double(const CL_StringRef8 &value);
00218
00224 static double ucs2_to_double(const CL_StringRef16 &value);
00225
00231 static CL_String int_to_text(int value);
00232
00238 static CL_String8 int_to_local8(int value);
00239
00245 static CL_String16 int_to_ucs2(int value);
00246
00253 static int text_to_int(const CL_StringRef &value, int base = 10);
00254
00261 static int local8_to_int(const CL_StringRef8 &value, int base = 10);
00262
00269 static int ucs2_to_int(const CL_StringRef16 &value, int base = 10);
00270
00276 static CL_String uint_to_text(unsigned int value);
00277
00283 static CL_String8 uint_to_local8(unsigned int value);
00284
00290 static CL_String16 uint_to_ucs2(unsigned int value);
00291
00292 static unsigned int text_to_uint(const CL_StringRef &value, int base = 10);
00293
00294 static unsigned int local8_to_uint(const CL_StringRef8 &value, int base = 10);
00295
00296 static unsigned int ucs2_to_uint(const CL_StringRef16 &value, int base = 10);
00297
00303 static CL_String ll_to_text(long long value);
00304
00310 static CL_String8 ll_to_local8(long long value);
00311
00317 static CL_String16 ll_to_ucs2(long long value);
00318
00325 static long long text_to_ll(const CL_StringRef &value, int base = 10);
00326
00333 static long long local8_to_ll(const CL_StringRef8 &value, int base = 10);
00334
00341 static long long ucs2_to_ll(const CL_StringRef16 &value, int base = 10);
00342
00348 static CL_String ull_to_text(unsigned long long value);
00349
00355 static CL_String8 ull_to_local8(unsigned long long value);
00356
00362 static CL_String16 ull_to_ucs2(unsigned long long value);
00363
00370 static unsigned long long text_to_ull(const CL_StringRef &value, int base = 10);
00371
00378 static unsigned long long local8_to_ull(const CL_StringRef8 &value, int base = 10);
00379
00386 static unsigned long long ucs2_to_ull(const CL_StringRef16 &value, int base = 10);
00387
00393 static CL_String bool_to_text(bool value);
00394
00400 static CL_String8 bool_to_local8(bool value);
00401
00407 static CL_String16 bool_to_ucs2(bool value);
00408
00414 static bool text_to_bool(const CL_StringRef &value);
00415
00421 static bool local8_to_bool(const CL_StringRef8 &value);
00422
00428 static bool ucs2_to_bool(const CL_StringRef16 &value);
00429
00435 static CL_String8 text_to_cp437(const CL_StringRef &text);
00436
00442 static CL_String8 ucs2_to_cp437(const CL_StringRef16 &text);
00443
00449 static CL_String cp437_to_text(const CL_StringRef8 &cp437);
00450
00456 static CL_String16 cp437_to_ucs2(const CL_StringRef8 &cp437);
00457
00463 static CL_String8 text_to_local8(const CL_StringRef &text);
00464
00470 static CL_String8 text_to_utf8(const CL_StringRef &text);
00471
00477 static CL_String8 ucs2_to_latin1(const CL_StringRef16 &ucs2);
00478
00484 static CL_String8 ucs2_to_latin9(const CL_StringRef16 &ucs2);
00485
00491 static CL_String8 ucs2_to_local8(const CL_StringRef16 &ucs2);
00492
00498 static CL_String8 ucs2_to_utf8(const CL_StringRef16 &ucs2);
00499
00505 static CL_String local8_to_text(const CL_StringRef8 &local8);
00506
00512 static CL_String ucs2_to_text(const CL_StringRef16 &ucs2);
00513
00519 static CL_String16 latin1_to_ucs2(const CL_StringRef8 &latin1);
00520
00526 static CL_String16 latin9_to_ucs2(const CL_StringRef8 &latin9);
00527
00533 static CL_String16 local8_to_ucs2(const CL_StringRef8 &local8);
00534
00540 static CL_String16 utf8_to_ucs2(const CL_StringRef8 &utf8);
00541
00547 static CL_String utf8_to_text(const CL_StringRef8 &utf8);
00548
00549 enum BOMType
00550 {
00551 bom_none,
00552 bom_utf32_be,
00553 bom_utf32_le,
00554 bom_utf16_be,
00555 bom_utf16_le,
00556 bom_utf8
00557 };
00558
00565 static BOMType detect_bom(const void *data, CL_String::size_type length);
00566
00567 #ifdef __cplusplus_cli
00568
00569
00570
00571
00572
00573 static CL_String clr_to_text(const System::String ^str)
00574 {
00575 return ucs2_to_utf8(clr_to_ucs2(str));
00576 }
00577
00578 static System::String ^text_to_clr(const CL_StringRef &str)
00579 {
00580 return ucs2_to_clr(utf8_to_ucs2(str));
00581 }
00582
00588 static CL_String16 clr_to_ucs2(const System::String ^str)
00589 {
00590 cli::pin_ptr<const wchar_t> chars = PtrToStringChars(str);
00591 return CL_String16(chars);
00592 }
00593
00594 static System::String ^ucs2_to_clr(const CL_StringRef16 &str)
00595 {
00596 return gcnew System::String(str.c_str());
00597 }
00598 #endif
00599
00603
00604 private:
00605 static const char trailing_bytes_for_utf8[256];
00606
00607 static const unsigned char bitmask_leadbyte_for_utf8[6];
00609 };
00610
00611 #ifdef __cplusplus_cli
00612 #pragma managed(pop)
00613 #endif
00614