diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llstring.h | 90 |
1 files changed, 28 insertions, 62 deletions
diff --git a/linden/indra/llcommon/llstring.h b/linden/indra/llcommon/llstring.h index 5f48580..70f7d54 100644 --- a/linden/indra/llcommon/llstring.h +++ b/linden/indra/llcommon/llstring.h | |||
@@ -2,6 +2,8 @@ | |||
2 | * @file llstring.h | 2 | * @file llstring.h |
3 | * @brief String utility functions and LLString class. | 3 | * @brief String utility functions and LLString class. |
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
6 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | 7 | * Copyright (c) 2001-2007, Linden Research, Inc. |
6 | * | 8 | * |
7 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
@@ -24,22 +26,12 @@ | |||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | 26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO |
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | 27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, |
26 | * COMPLETENESS OR PERFORMANCE. | 28 | * COMPLETENESS OR PERFORMANCE. |
29 | * $/LicenseInfo$ | ||
27 | */ | 30 | */ |
28 | 31 | ||
29 | #ifndef LL_LLSTRING_H | 32 | #ifndef LL_LLSTRING_H |
30 | #define LL_LLSTRING_H | 33 | #define LL_LLSTRING_H |
31 | 34 | ||
32 | #include "stdtypes.h" | ||
33 | #include "llerror.h" | ||
34 | #include "llfile.h" | ||
35 | #include <algorithm> | ||
36 | #include <map> | ||
37 | #include <stdio.h> | ||
38 | #include <ctype.h> | ||
39 | #include <stdlib.h> | ||
40 | #include <errno.h> | ||
41 | #include <math.h> | ||
42 | #include <stdarg.h> /* for vsnprintf */ | ||
43 | #if LL_LINUX || LL_SOLARIS | 35 | #if LL_LINUX || LL_SOLARIS |
44 | #include <wctype.h> | 36 | #include <wctype.h> |
45 | #include <wchar.h> | 37 | #include <wchar.h> |
@@ -280,9 +272,6 @@ public: | |||
280 | */ | 272 | */ |
281 | static void _makeASCII(std::basic_string<T>& string); | 273 | static void _makeASCII(std::basic_string<T>& string); |
282 | 274 | ||
283 | static BOOL read(std::basic_string<T>& string, const char* filename); /*Flawfinder: ignore*/ | ||
284 | static BOOL write(std::basic_string<T>& string, const char* filename); | ||
285 | |||
286 | // Conversion to other data types | 275 | // Conversion to other data types |
287 | static BOOL convertToBOOL(const std::basic_string<T>& string, BOOL& value); | 276 | static BOOL convertToBOOL(const std::basic_string<T>& string, BOOL& value); |
288 | static BOOL convertToU8(const std::basic_string<T>& string, U8& value); | 277 | static BOOL convertToU8(const std::basic_string<T>& string, U8& value); |
@@ -332,6 +321,18 @@ template<class T> LLStringBase<T> LLStringBase<T>::null; | |||
332 | typedef LLStringBase<char> LLString; | 321 | typedef LLStringBase<char> LLString; |
333 | typedef LLStringBase<llwchar> LLWString; | 322 | typedef LLStringBase<llwchar> LLWString; |
334 | 323 | ||
324 | //@ Use this where we want to disallow input in the form of "foo" | ||
325 | // This is used to catch places where english text is embedded in the code | ||
326 | // instead of in a translatable XUI file. | ||
327 | class LLStringExplicit : public LLString | ||
328 | { | ||
329 | public: | ||
330 | explicit LLStringExplicit(const char* s) : LLString(s) {} | ||
331 | LLStringExplicit(const LLString& s) : LLString(s) {} | ||
332 | LLStringExplicit(const std::string& s) : LLString(s) {} | ||
333 | LLStringExplicit(const std::string& s, size_type pos, size_type n = std::string::npos) : LLString(s, pos, n) {} | ||
334 | }; | ||
335 | |||
335 | struct LLDictionaryLess | 336 | struct LLDictionaryLess |
336 | { | 337 | { |
337 | public: | 338 | public: |
@@ -347,7 +348,7 @@ public: | |||
347 | */ | 348 | */ |
348 | 349 | ||
349 | /** | 350 | /** |
350 | * @breif chop off the trailing characters in a string. | 351 | * @brief chop off the trailing characters in a string. |
351 | * | 352 | * |
352 | * This function works on bytes rather than glyphs, so this will | 353 | * This function works on bytes rather than glyphs, so this will |
353 | * incorrectly truncate non-single byte strings. | 354 | * incorrectly truncate non-single byte strings. |
@@ -373,6 +374,16 @@ std::string ll_safe_string(const char* in); | |||
373 | */ | 374 | */ |
374 | U8 hex_as_nybble(char hex); | 375 | U8 hex_as_nybble(char hex); |
375 | 376 | ||
377 | /** | ||
378 | * @brief read the contents of a file into a string. | ||
379 | * | ||
380 | * Since this function has no concept of character encoding, most | ||
381 | * anything you do with this method ill-advised. Please avoid. | ||
382 | * @param str [out] The string which will have. | ||
383 | * @param filename The full name of the file to read. | ||
384 | * @return Returns true on success. If false, str is unmodified. | ||
385 | */ | ||
386 | bool _read_file_into_string(std::string& str, const char* filename); | ||
376 | 387 | ||
377 | /** | 388 | /** |
378 | * Unicode support | 389 | * Unicode support |
@@ -933,8 +944,6 @@ void LLStringBase<T>::replaceNonstandardASCII( std::basic_string<T>& string, T r | |||
933 | template<class T> | 944 | template<class T> |
934 | void LLStringBase<T>::replaceTabsWithSpaces( std::basic_string<T>& str, size_type spaces_per_tab ) | 945 | void LLStringBase<T>::replaceTabsWithSpaces( std::basic_string<T>& str, size_type spaces_per_tab ) |
935 | { | 946 | { |
936 | llassert( spaces_per_tab >= 0 ); | ||
937 | |||
938 | const T TAB = '\t'; | 947 | const T TAB = '\t'; |
939 | const T SPACE = ' '; | 948 | const T SPACE = ' '; |
940 | 949 | ||
@@ -1037,11 +1046,10 @@ void LLStringBase<T>::copy( T* dst, const T* src, size_type dst_size ) | |||
1037 | template<class T> | 1046 | template<class T> |
1038 | void LLStringBase<T>::copyInto(std::basic_string<T>& dst, const std::basic_string<T>& src, size_type offset) | 1047 | void LLStringBase<T>::copyInto(std::basic_string<T>& dst, const std::basic_string<T>& src, size_type offset) |
1039 | { | 1048 | { |
1040 | llassert( offset <= dst.length() ); | ||
1041 | |||
1042 | // special case - append to end of string and avoid expensive (when strings are large) string manipulations | ||
1043 | if ( offset == dst.length() ) | 1049 | if ( offset == dst.length() ) |
1044 | { | 1050 | { |
1051 | // special case - append to end of string and avoid expensive | ||
1052 | // (when strings are large) string manipulations | ||
1045 | dst += src; | 1053 | dst += src; |
1046 | } | 1054 | } |
1047 | else | 1055 | else |
@@ -1070,48 +1078,6 @@ BOOL LLStringBase<T>::isHead( const std::basic_string<T>& string, const T* s ) | |||
1070 | } | 1078 | } |
1071 | } | 1079 | } |
1072 | 1080 | ||
1073 | //static | ||
1074 | template<class T> | ||
1075 | BOOL LLStringBase<T>::read(std::basic_string<T>& string, const char* filename) /*Flawfinder: ignore*/ | ||
1076 | { | ||
1077 | llifstream ifs(filename, llifstream::binary); | ||
1078 | if (!ifs.is_open()) | ||
1079 | { | ||
1080 | llinfos << "Unable to open file" << filename << llendl; | ||
1081 | return FALSE; | ||
1082 | } | ||
1083 | |||
1084 | std::basic_ostringstream<T> oss; | ||
1085 | |||
1086 | oss << ifs.rdbuf(); | ||
1087 | |||
1088 | string = oss.str(); | ||
1089 | |||
1090 | ifs.close(); | ||
1091 | return TRUE; | ||
1092 | } | ||
1093 | |||
1094 | //static | ||
1095 | template<class T> | ||
1096 | BOOL LLStringBase<T>::write(std::basic_string<T>& string, const char* filename) | ||
1097 | { | ||
1098 | #if LL_LINUX || LL_SOLARIS | ||
1099 | printf("STUBBED: LLStringBase<T>::write at %s:%d\n", __FILE__, __LINE__); | ||
1100 | #else | ||
1101 | llofstream ofs(filename, llofstream::binary); | ||
1102 | if (!ofs.is_open()) | ||
1103 | { | ||
1104 | llinfos << "Unable to open file" << filename << llendl; | ||
1105 | return FALSE; | ||
1106 | } | ||
1107 | |||
1108 | ofs << string; | ||
1109 | |||
1110 | ofs.close(); | ||
1111 | #endif | ||
1112 | return TRUE; | ||
1113 | } | ||
1114 | |||
1115 | template<class T> | 1081 | template<class T> |
1116 | BOOL LLStringBase<T>::convertToBOOL(const std::basic_string<T>& string, BOOL& value) | 1082 | BOOL LLStringBase<T>::convertToBOOL(const std::basic_string<T>& string, BOOL& value) |
1117 | { | 1083 | { |