MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / String

Class String

source/core/StarString.hpp:29–295  ·  view source on GitHub ↗

A Unicode string class, which is a basic UTF-8 aware wrapper around std::string. Provides methods for accessing UTF-32 "Char" type, which provides access to each individual code point. Printing, hashing, copying, and in-order access should be basically as fast as std::string, but the more complex string processing methods may be much worse. All case sensitive / insensitive functionality is base

Source from the content-addressed store, hash-verified

27// case insensitivity is really only appropriate for code / script processing,
28// not for general strings.
29class String {
30public:
31 typedef Utf32Type Char;
32
33 // std::basic_string equivalent that guarantees const access time for
34 // operator[], etc
35 typedef std::basic_string<Char> WideString;
36
37 typedef U8ToU32Iterator<std::string::const_iterator> const_iterator;
38 typedef Char value_type;
39 typedef value_type const& const_reference;
40
41 enum CaseSensitivity {
42 CaseSensitive,
43 CaseInsensitive
44 };
45
46 // Space, horizontal tab, newline, carriage return, and BOM / ZWNBSP
47 static bool isSpace(Char c);
48 static bool isAsciiNumber(Char c);
49 static bool isAsciiLetter(Char c);
50
51 // These methods only actually work on unicode characters below 127, i.e.
52 // ASCII subset.
53 static Char toLower(Char c);
54 static Char toUpper(Char c);
55 static bool charEqual(Char c1, Char c2, CaseSensitivity cs);
56
57 // Join two strings together with a joiner, so that only one instance of the
58 // joiner is in between the left and right strings. For example, joins "foo"
59 // and "bar" with "?" to produce "foo?bar". Gets rid of repeat joiners, so
60 // "foo?" and "?bar" with "?" also becomes "foo?bar". Also, if left or right
61 // is empty, does not add a joiner, for example "" and "baz" joined with "?"
62 // produces "baz".
63 static String joinWith(String const& join, String const& left, String const& right);
64 template <typename... StringType>
65 static String joinWith(String const& join, String const& first, String const& second, String const& third, StringType const&... rest);
66
67 String();
68 String(String const& s);
69 String(String&& s);
70
71 // These assume utf8 input
72 String(char const* s);
73 String(char const* s, size_t n);
74 String(std::string const& s);
75 String(std::string&& s);
76
77 String(std::wstring const& s);
78 String(Char const* s);
79 String(Char const* s, size_t n);
80 String(Char c, size_t n);
81
82 explicit String(Char c);
83
84 // const& to internal utf8 data
85 std::string const& utf8() const;
86 std::string takeUtf8();

Callers 15

renderPortraitMethod · 0.85
liquidDescriptionMethod · 0.85
produceSystemMethod · 0.85
inspectionLogNameMethod · 0.85
setSecretPropertyMethod · 0.85
connectMethod · 0.85
updateMethod · 0.85
TMXTileLayerMethod · 0.85
WorldStructureMethod · 0.85
miningSoundMethod · 0.85
variantFromBiomeItemFunction · 0.85
buildLayerMethod · 0.85

Calls 1

SliceIndexClass · 0.85

Tested by 5

TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68
TESTFunction · 0.68