ComSDK
 Указатель Классы Пространства имен Функции Переменные Определения типов Перечисления Элементы перечислений Друзья Группы Страницы
stringtools.h
1 //===========================================================================
2 #ifndef comfrm_StringToolsH
3 #define comfrm_StringToolsH
4 //===========================================================================
5 // Заготовка модуля StringTools была сгенерирована CASE средством разработки SA2-DE.
6 // Все права защищены. (2010)
7 //
8 // В данном файле представлен исходный текст основного заголовочного файла модуля.
9 //
10 // ======================================= //
11 // Параметры новой разработки.
12 // ======================================= //
13 // Имя комплекса: CommonTools (com)
14 // Имя решения: GCAD_3 (gc3) (прочерк если модуль относится лишь к комплексу)
15 // Имя проекта: System (sys) (прочерк если модуль относится лишь к решению)
16 // Полный SID: comgc3sys
17 // Время создания: 17:32:39
18 // Дата создания: 18.08.2010
19 // ======================================= //
20 // ============================================================================================ //
21 // Параметры ревизии(версии):
22 // ============================================================================================ //
23 // [prd]Period: 8/2010
24 // [aut]Author: Александр Соколов
25 // [did]DeveloperID: sa
26 // [pid]ProblemID: 00001
27 // [rvs = did.date.pid]Revision: //#sa.18.08.2010.00001
28 // [dsc]Description: Работа со строками.
29 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
30 // ============================================================================================ //
31 // [prd]Period: 12/2013
32 // [aut]Author: Щетинин Виталий
33 // [did]DeveloperID: sv
34 // [pid]ProblemID: 00002
35 // [rvs = did.date.pid]Revision: //#sv.13.12.2013.00002
36 // [dsc]Description: double_to_str,stingToWstring,wstringToString
37 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
38 // ============================================================================================ //
39 // [prd]Period: 08/2014
40 // [aut]Author: Соколов Александр
41 // [did]DeveloperID: sa
42 // [pid]ProblemID: 00011
43 // [rvs = did.date.pid]Revision: //#sa.2014-08-28.00011
44 // [dsc]Description: Исправил неверное формирование запроса к БД в случае наличия в данных специального символа апостроф (')!
45 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
46 // ============================================================================================ //
47 
48 //========================================================================
49 // ДОПОЛНИТЕЛЬНЫЕ ПОДКЛЮЧЕНИЯ (Типы и модули, необходимые для .h - файла)
50 //------------------------------------------------------------------------
51 #include "libtools.h"
52 
53 #include <string>
54 #include <sstream>
55 #include <algorithm>
56 #include <map>
57 //========================================================================
58 namespace com
59 {
67  namespace str
68  {
72  template<class SomeType>
73  std::string toString(SomeType p_value)
74  {
75  std::stringstream ss;
76  ss << p_value;
77  return ss.str();
78  }
79 
83  template<>
84  MAC_DLLEXPORT std::string toString(bool p_value);
85 
91  template<class SomeType>
92  SomeType fromString(const std::string& p_str, bool* p_ok = 0)
93  {
94  SomeType value;
95  std::stringstream ss(p_str);
96  ss >> value;
97  if (p_ok)
98  *p_ok = (ss.fail() == false);
99  return value;
100  }
101 
105  template<>
106  MAC_DLLEXPORT bool fromString<bool>(const std::string& p_str, bool* p_ok);
107 
115  MAC_DLLEXPORT bool removeComments(const std::string& p_source_str, const std::string& p_comment_separator,
116  std::string& o_dest_str);
117 
124  MAC_DLLEXPORT std::string trim(std::string p_str, std::string p_whitespaces = " \t\n\r");
125 
131  MAC_DLLEXPORT std::string ltrim(std::string p_str, std::string p_whitespaces = " \t\n\r");
132 
138  MAC_DLLEXPORT std::string rtrim(std::string p_str, std::string p_whitespaces = " \t\n\r");
139 
147  MAC_DLLEXPORT std::string replaceAll(const std::string& p_str, const std::string& p_from, const std::string& p_to);
148 
158  MAC_DLLEXPORT bool paramValueSplit(const std::string& p_pair, const std::string& p_delimeter,
159  std::string &o_param, std::string &o_value);
163  MAC_DLLEXPORT bool paramValueSplit(const std::string& p_pair, char p_delimeter,
164  std::string &o_param, std::string &o_value);
165 
173  MAC_DLLEXPORT std::vector< std::string > split(const std::string& p_str, char p_delimeter);
174 
181  MAC_DLLEXPORT std::map< std::string, std::string > doubleSplit(const std::string& str, char macroDelimeter,
182  char microDelimiter);
183 
187  MAC_DLLEXPORT std::string join(const std::string& p_delimeter, const std::vector< std::string >& p_strings);
188 
194  MAC_DLLEXPORT int countSymbols(const std::string& p_str);
195  }
196 }
197 
198 //===========================================================================
199 #endif
200 //===========================================================================
SomeType fromString(const std::string &p_str, bool *p_ok=0)
Definition: stringtools.h:92
MAC_DLLEXPORT std::vector< std::string > split(const std::string &p_str, char p_delimeter)
MAC_DLLEXPORT bool fromString< bool >(const std::string &p_str, bool *p_ok)
MAC_DLLEXPORT std::string rtrim(std::string p_str, std::string p_whitespaces=" \t\n\r")
Definition: stringtools.cpp:95
MAC_DLLEXPORT std::string ltrim(std::string p_str, std::string p_whitespaces=" \t\n\r")
Definition: stringtools.cpp:88
MAC_DLLEXPORT std::string replaceAll(const std::string &p_str, const std::string &p_from, const std::string &p_to)
Definition: stringtools.cpp:50
MAC_DLLEXPORT bool removeComments(const std::string &p_source_str, const std::string &p_comment_separator, std::string &o_dest_str)
Definition: stringtools.cpp:63
MAC_DLLEXPORT std::map< std::string, std::string > doubleSplit(const std::string &str, char macroDelimeter, char microDelimiter)
Definition: stringtools.cpp:269
MAC_DLLEXPORT std::string trim(std::string p_str, std::string p_whitespaces=" \t\n\r")
Definition: stringtools.cpp:82
MAC_DLLEXPORT std::string join(const std::string &p_delimeter, const std::vector< std::string > &p_strings)
Definition: stringtools.cpp:166
MAC_DLLEXPORT int countSymbols(const std::string &p_str)
Definition: stringtools.cpp:222
MAC_DLLEXPORT bool paramValueSplit(const std::string &p_pair, const std::string &p_delimeter, std::string &o_param, std::string &o_value)
Definition: stringtools.cpp:102
std::string toString(SomeType p_value)
Definition: stringtools.h:73