Str.h
1 //##################################################################################################
2 //
3 // Ceetron Desktop Components
4 // Component: Core
5 //
6 // --------------------------------------------------------------------------------------------
7 // Copyright (C) 2013, Ceetron AS
8 // This is UNPUBLISHED PROPRIETARY SOURCE CODE of Ceetron AS. The contents of this file may
9 // not be disclosed to third parties, copied or duplicated in any form, in whole or in part,
10 // without the prior written permission of Ceetron AS.
11 //##################################################################################################
12 
13 #pragma once
14 
15 #include "CeeCore/Base.h"
16 
17 #include <string>
18 #include <vector>
19 
20 namespace cee {
21 
22 
23 //==================================================================================================
24 //
25 // String class
26 //
27 //==================================================================================================
28 class CEE_CORE_EXPORT Str
29 {
30 public:
31  Str();
32  Str(const Str& other);
33  Str(const char* theString);
34  explicit Str(const wchar_t* theString);
35  explicit Str(const std::string& theString);
36  explicit Str(const std::wstring& theString);
37  explicit Str(char c);
38  ~Str();
39 
40  Str& operator=(const Str& other);
41 
42  bool operator==(const Str& rhs) const;
43  bool operator!=(const Str& rhs) const;
44  bool operator<(const Str& rhs) const;
45  const Str operator+(const Str& rhs) const;
46  Str& operator+=(const Str& rhs);
47 
48  Str toLower() const;
49  Str toUpper() const;
50  Str trimmedRight() const;
51  Str trimmedLeft() const;
52  Str trimmed() const;
53  Str simplified() const;
54 
55  std::vector<Str> split(const Str& delimiters = " ") const;
56  size_t find(const Str& str, size_t start = 0) const;
57  bool startsWith(const Str& str) const;
58  Str subStr(size_t start, size_t length = npos) const;
59  void replace(const Str& before, const Str& after);
60 
61  const wchar_t* c_str() const;
62  std::string toStdString() const;
63  std::wstring toStdWString() const;
64  std::string toUtf8() const;
65 
66  bool isEmpty() const;
67  size_t size() const;
68 
69  static Str number(int n);
70  static Str number(unsigned int n);
71  static Str number(float n, char format = 'g', int precision = -1);
72  static Str number(double n, char format = 'g', int precision = -1);
73  static Str numberFromAddress(const void* ptr);
74 
75  double toDouble(bool* ok = NULL) const;
76  double toDouble(double defaultValue) const;
77  float toFloat(bool* ok = NULL) const;
78  float toFloat(float defaultValue) const;
79  int toInt(bool* ok = NULL) const;
80  int toInt(int defaultValue) const;
81  unsigned int toUInt(bool* ok = NULL) const;
82  unsigned int toUInt(unsigned int defaultValue) const;
83 
84  Str arg(const Str& a, int fieldWidth = 0, char fillChar = ' ') const;
85  Str arg(char a, int fieldWidth = 0, char fillChar = ' ') const;
86  Str arg(int a, int fieldWidth = 0, char fillChar = ' ') const;
87  Str arg(int64_t a, int fieldWidth = 0, char fillChar = ' ') const;
88  Str arg(unsigned int a, int fieldWidth = 0, char fillChar = ' ') const;
89  Str arg(uint64_t a, int fieldWidth = 0, char fillChar = ' ') const;
90  Str arg(float a, int fieldWidth = 0, char format = 'g', int precision = -1, char fillChar = ' ') const;
91  Str arg(double a, int fieldWidth = 0, char format = 'g', int precision = -1, char fillChar = ' ') const;
92 #ifdef CEE_OSX
93  Str arg(size_t a, int fieldWidth = 0, char fillChar = ' ') const;
94 #endif
95 
96  void swap(Str& other);
97 
98  bool matches(const Str& wildcard) const;
99 
100  const void* unspecifiedWCharPointer() const;
101  static Str fromUnspecifiedWCharPointer(const void* voidPtr);
102 
103  static const size_t npos;
104 private:
106  CEE_PRIVATE_IMPL(Str);
107 };
108 
109 Str CEE_CORE_EXPORT operator+(const char* str1, const Str& str2);
110 
111 } // namespace cee
cee::Str operator+(const char *str1, const cee::Str &str2)
Global operator to allow a const char + a cee::Str.
Definition: Str.cpp:817
Namespace cee contains all functionality and structures under the Core component. ...
Definition: AppAssert.cpp:18
static const size_t npos
Same as std::string::npos. This value, when used as the value for a count parameter n in string's mem...
Definition: Str.h:103
A general unicode based string class.
Definition: Str.h:28
bool operator!=(const PtrRef< T1 > &a, const PtrRef< T2 > &b)
Returns true if the internal pointers of refs a and b are different.
Definition: PtrRef.h:58
bool operator==(const PtrRef< T1 > &a, const PtrRef< T2 > &b)
Returns true if the internal pointers of refs a and b are equal.
Definition: PtrRef.h:57
void swap(PtrRef< T > &a, PtrRef< T > &b)
Swap contents of a and b. Matches signature of std::swap().
Definition: PtrRef.h:66