SDL Window Engine  20200905
swe_cstring.h
1 /***************************************************************************
2  * Copyright (C) 2017 by SWE team <sdl.window.engine@gmail.com> *
3  * *
4  * Part of the SWE: SDL Window Engine: *
5  * https://github.com/AndreyBarmaley/sdl-window-engine *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
23 #ifndef _SWE_CSTRING_
24 #define _SWE_CSTRING_
25 
26 #include <list>
27 #include <string>
28 #include <functional>
29 
30 #include "swe_types.h"
31 
33 namespace SWE
34 {
36  struct StringList : std::list<std::string>
37  {
38  StringList();
39  StringList(const std::list<std::string> &);
40  StringList(const std::initializer_list<const char*> &);
41  StringList(const StringList &);
42 
43  StringList(StringList &&) noexcept;
44  StringList(std::list<std::string> &&) noexcept;
45 
46  StringList & operator= (const StringList &);
47  StringList & operator= (StringList &&) noexcept;
48  StringList & operator= (std::list<std::string> &&) noexcept;
49 
50  size_t maxStringWidth(void) const;
51  size_t totalStringsWidth(void) const;
52 
53  std::string join(void) const;
54  std::string join(const std::string &) const;
55 
56  StringList & append(const std::string &);
57  StringList & append(const StringList &);
58 
59  StringList & operator<< (const std::string &);
60  StringList & operator<< (const StringList &);
61  };
62 
63  namespace String
64  {
65  const char* Bool(bool);
66  std::string ucFirst(std::string);
67  std::string toLower(std::string);
68  std::string toUpper(std::string);
69  int toInt(const std::string &, bool* = nullptr);
70  long int toLong(const std::string &, bool* = nullptr);
71  double toDouble(const std::string &, bool* = nullptr);
72  int index(const std::string &, int);
73 
74  std::string trimmed(const std::string &);
75  std::string chomp(const std::string &);
76  std::string time(void);
77  std::string time(const time_t &);
78  std::string strftime(const std::string &);
79  std::string strftime(const std::string &, const time_t &);
80 
81  std::string escaped(const std::string &, bool quote = false);
82  std::string unescaped(std::string);
83 
84  bool compareInSensitive(const std::string &, const std::string &);
85 
86  std::string replace(const std::string &, const char*, const std::string &);
87  std::string replace(const std::string &, const char*, int);
88 
89  StringList split(const std::string &, int);
90  StringList split(const std::string & str, std::function<bool(int)>);
91  StringList split(const std::string & str, const std::string & sep);
92 
93  std::string hex(u64 value, int width = 8);
94  std::string hex64(u64 value);
95  std::string pointer(const void*);
96 
97  std::string number(int);
98  std::string number(double, int prec);
99 
100  const char* sign(int);
101  }
102 
104  class StringFormat : public std::string
105  {
106  int cur;
107 
108  public:
109  StringFormat(const std::string &, size_t reserver = 0);
110 
111  StringFormat & arg(const std::string &);
112  StringFormat & arg(const char*);
113  StringFormat & arg(int);
114  StringFormat & arg(double, int prec);
115 
116  StringFormat & replace(const char*, int);
117  StringFormat & replace(const char*, const std::string &);
118  StringFormat & replace(const char*, double, int prec);
119  };
120 
121 } // SWE
122 #endif
пространство SWE.
Definition: swe_binarybuf.cpp:30
класс списка строк
Definition: swe_cstring.h:36
класс форматной строки
Definition: swe_cstring.h:104