1 | /*
|
---|
2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
4 | */
|
---|
5 |
|
---|
6 | /**
|
---|
7 | @file FUString.h
|
---|
8 | This file includes FUStringBuilder.h and FUStringConversion.h
|
---|
9 | and defines important string-related macros and inline functions.
|
---|
10 | */
|
---|
11 |
|
---|
12 | #ifndef _FU_STRING_H_
|
---|
13 | #define _FU_STRING_H_
|
---|
14 |
|
---|
15 | /** A dynamically-sized array of Unicode strings. */
|
---|
16 | typedef vector<fstring> FStringList;
|
---|
17 |
|
---|
18 | /** A dynamically-sized array of simple strings. */
|
---|
19 | typedef vector<string> StringList;
|
---|
20 |
|
---|
21 | /** Returns whether two 8-bit strings are equivalent. This is a case-sensitive comparison.
|
---|
22 | @param sz1 The first 8-bit string to compare.
|
---|
23 | @param sz2 The second 8-bit string to compare.
|
---|
24 | @return Whether the two 8-bit strings are equivalent. */
|
---|
25 | inline bool IsEquivalent(const char* sz1, const char* sz2) { return strcmp(sz1, sz2) == 0; }
|
---|
26 | inline bool IsEquivalent(const string& sz1, const char* sz2) { return strcmp(sz1.c_str(), sz2) == 0; } /**< See above. */
|
---|
27 | inline bool IsEquivalent(const char* sz1, const string& sz2) { return strcmp(sz1, sz2.c_str()) == 0; } /**< See above. */
|
---|
28 | inline bool IsEquivalent(const string& sz1, const string& sz2) { return strcmp(sz1.c_str(), sz2.c_str()) == 0; } /**< See above. */
|
---|
29 |
|
---|
30 | /** Returns whether two 8-bit strings are equivalent. This is a case-sensitive comparison.
|
---|
31 | @param sz1 The first 8-bit string to compare.
|
---|
32 | @param sz2 The second 8-bit string to compare.
|
---|
33 | @return Whether the two 8-bit strings are equivalent. */
|
---|
34 | inline bool operator==(const string& sz1, const char* sz2) { return strcmp(sz1.c_str(), sz2) == 0; }
|
---|
35 |
|
---|
36 | /** Appends a signed integer to an 8-bit string. This function is meant
|
---|
37 | for debugging purposes. Use the FUStringBuilder class instead.
|
---|
38 | @param sz1 The 8-bit string prefix.
|
---|
39 | @param i The signed integer to convert and append.
|
---|
40 | @return The final 8-bit string. */
|
---|
41 | FCOLLADA_EXPORT string operator+(const string& sz1, int32 i);
|
---|
42 |
|
---|
43 | #ifdef UNICODE
|
---|
44 | /** Returns whether two Unicode strings are equivalent. This is a case-sensitive comparison.
|
---|
45 | @param sz1 The first Unicode string to compare.
|
---|
46 | @param sz2 The second Unicode string to compare.
|
---|
47 | @return Whether the two Unicode strings are equivalent. */
|
---|
48 | inline bool IsEquivalent(const fchar* sz1, const fchar* sz2) { return fstrcmp(sz1, sz2) == 0; }
|
---|
49 | inline bool IsEquivalent(const fstring& sz1, const fchar* sz2) { return fstrcmp(sz1.c_str(), sz2) == 0; } /**< See above. */
|
---|
50 | inline bool IsEquivalent(const fchar* sz1, const fstring& sz2) { return fstrcmp(sz1, sz2.c_str()) == 0; } /**< See above. */
|
---|
51 | inline bool IsEquivalent(const fstring& sz1, const fstring& sz2) { return fstrcmp(sz1.c_str(), sz2.c_str()) == 0; } /**< See above. */
|
---|
52 |
|
---|
53 | /** Returns whether two Unicode strings are equivalent. This is a case-sensitive comparison.
|
---|
54 | @param sz1 The first Unicode string to compare.
|
---|
55 | @param sz2 The second Unicode string to compare.
|
---|
56 | @return Whether the two Unicode strings are equivalent. */
|
---|
57 | inline bool operator==(const fstring& sz1, const fchar* sz2) { return fstrcmp(sz1.c_str(), sz2) == 0; }
|
---|
58 |
|
---|
59 | /** Appends a signed integer to a Unicode string. This function is meant
|
---|
60 | for debugging purposes. Use the FUStringBuilder class instead.
|
---|
61 | @param sz1 The Unicode string prefix.
|
---|
62 | @param i The signed integer to convert and append.
|
---|
63 | @return The final Unicode string. */
|
---|
64 | FCOLLADA_EXPORT fstring operator+(const fstring& sz1, int32 i);
|
---|
65 | #endif // UNICODE
|
---|
66 |
|
---|
67 | // Include the main string modification classes.
|
---|
68 | #include "FUtils/FUStringBuilder.h"
|
---|
69 | #include "FUtils/FUStringConversion.h"
|
---|
70 |
|
---|
71 | /** A Unicode string from a constant 8-bit string. */
|
---|
72 | #define FS(a) fstring(FC(a))
|
---|
73 | /** A Unicode string from any convertable value: string, vector-type or simple numeric. */
|
---|
74 | #define TO_FSTRING(a) FUStringConversion::ToFString(a)
|
---|
75 | /** An 8-bit string from any convertable value: Unicode string, vector-type or simple numeric. */
|
---|
76 | #define TO_STRING(a) FUStringConversion::ToString(a)
|
---|
77 |
|
---|
78 | /** An empty UTF-8 string. This string is returned in many functions when there is an error. */
|
---|
79 | extern FCOLLADA_EXPORT const string emptyString;
|
---|
80 | /** An empty Unicode string. This string is returned in many functions when there is an error. */
|
---|
81 | extern FCOLLADA_EXPORT const fstring emptyFString;
|
---|
82 |
|
---|
83 | /** Returns whether a string builder and a string are equivalent. This is a case-sensitive comparison.
|
---|
84 | @param builder The string builder to compare.
|
---|
85 | @param sz The string to compare.
|
---|
86 | @return Whether the two strings are equivalent. */
|
---|
87 | inline bool IsEquivalent(FUSStringBuilder& builder, const char* sz) { return IsEquivalent(builder.ToCharPtr(), sz); }
|
---|
88 | inline bool IsEquivalent(FUSStringBuilder& builder, const string& sz) { return IsEquivalent(builder.ToCharPtr(), sz.c_str()); } /**< See above. */
|
---|
89 | inline bool IsEquivalent(FUStringBuilder& builder, const fchar* sz) { return IsEquivalent(builder.ToCharPtr(), sz); } /**< See above. */
|
---|
90 | inline bool IsEquivalent(FUStringBuilder& builder, const fstring& sz) { return IsEquivalent(builder.ToCharPtr(), sz.c_str()); } /**< See above. */
|
---|
91 |
|
---|
92 | #endif // _FU_STRING_H_
|
---|