TNB Library
TnbStrVector.h
[詳解]
1#pragma once
15#include "TnbStr.h"
16#include "TnbVector.h"
17
18
19
20//TNB Library
21namespace TNB
22{
23
24
25
32
33
34
41
42
43
50
51
52
63inline CWordVector StringToWordVector(LPCSTR lpszAscii)
64{
65 CWordVector vw;
66 LPCSTR P = lpszAscii;
67 while ( P != NULL && *P != 0 )
68 {
69 char c = *P++;
70 BYTE b = c;
71 if ( STRLIB::GetCharSize(c) == 2 )
72 {
73 BYTE d = *P++;
74 vw.Add(static_cast<WORD>((b << 8) | d));
75 }
76 else
77 {
78 vw.Add(b);
79 }
80 }
81 return vw;
82}
83
84
85
95inline CWordVector StringToWordVector(LPCWSTR lpszUnicode)
96{
97 CWordVector vw;
98 vw.SetElements(STRLIB::GetLen(lpszUnicode), reinterpret_cast<const WORD*>(lpszUnicode));
99 return vw;
100}
101
102
103
114inline CStr StrVectorToStr(const CStrVector& vs, TCHAR sepaChar = '^')
115{
116 CStr str;
117 loop ( i, vs.GetSize() )
118 {
119 if ( i != 0 )
120 {
121 str += sepaChar;
122 }
123 str += vs[i];
124 }
125 return str;
126}
127
138inline CStrVector StrToStrVector(LPCTSTR lpsz, TCHAR sepaChar = '^')
139{
140 CStrVector vs;
141 if ( STRLIB::GetLen(lpsz) > 0 )
142 {
143 INDEX index = 0;
144 while ( true )
145 {
146 INT_PTR r = STRLIB::IndexOf(lpsz, sepaChar, index);
147 if ( r < 0 )
148 {
149 break;
150 }
151 CStr s;
152 s.SetFromLeft(&lpsz[index], static_cast<size_t>(r - index));
153 vs.Add(s);
154 index = static_cast<INDEX>(r + 1);
155 }
156 vs.Add(CStr(&lpsz[index]));
157 }
158 return vs;
159}
160
172inline CStr StrVectorToStrEx(const CStrVector& vs, TCHAR sepaChar = '^', TCHAR escChar = '\\')
173{
174 CStr str;
175 TCHAR aEsc[2] = { escChar, 0 };
176 TCHAR aEsc2[3] = { escChar, escChar, 0 };
177 TCHAR aSepa[3] = { escChar, sepaChar, 0 };
178 loop ( i, vs.GetSize() )
179 {
180 if ( i != 0 )
181 {
182 str += aSepa;
183 }
184 CStr s = vs[i];
185 s.Replace(aEsc, aEsc2);
186 str += s;
187 }
188 return str;
189}
190
201inline CStrVector StrToStrVectorEx(LPCTSTR lpsz, TCHAR sepaChar = '^', TCHAR escChar = '\\')
202{
203 CStrVector vs;
204 if ( lpsz != NULL && STRLIB::GetLen(lpsz) > 0 )
205 {
206 TCHAR aEsc[2] = { escChar, 0 };
207 TCHAR aEsc2[3] = { escChar, escChar, 0 };
208 TCHAR aSepa[3] = { escChar, sepaChar, 0 };
209 INDEX index = 0;
210 while ( true )
211 {
212 INT_PTR r = STRLIB::IndexOf(lpsz, aSepa, index);
213 if ( r < 0 )
214 {
215 break;
216 }
217 CStr s;
218 s.SetFromLeft(&lpsz[index], static_cast<size_t>(r - index));
219 s.Replace(aEsc2, aEsc);
220 vs.Add(s);
221 index = static_cast<INDEX>(r + 2);
222 }
223 CStr s = CStr(&lpsz[index]);
224 s.Replace(aEsc2, aEsc);
225 vs.Add(s);
226 }
227 return vs;
228}
229
245inline CStrVector operator%(const CStr& s1, const CStr& s2)
246{
247 CStrVector vs;
248 vs.Add(s1);
249 vs.Add(s2);
250 return vs;
251}
252
268inline CStrVector operator%(const CStrVector& vs, const CStr& s)
269{
270 CStrVector v = vs;
271 v.Add(s);
272 return v;
273}
274
275#ifdef __AFX_H__
276
284
293 inline CStrVector ToStrVector(const CStringArray& astr)
294 {
295 CStrVector vs;
296 size_t size = static_cast<size_t>(astr.GetSize());
297 vs.SetSize(size);
298 loop ( i, size )
299 {
300 vs.Set(i, CStr(astr[i]));
301 }
302 return vs;
303 }
304
305#endif
306
307
308
314#ifdef _DEBUG
315inline void TRACE_SV(const CStrVector& vs)
316{
317 loop ( i, vs )
318 {
319 ::OutputDebugString(vs[i] + _T("\n"));
320 }
321}
322#else
323#define TRACE_SV(XX)
324#endif
325
326
327
328}; // TNB
329
#define loop(VAR, CNT)
loop構文.
Definition: TnbDef.h:343
文字列管理関係のヘッダ
配列型情報管理関係のヘッダ
CStrT & SetFromLeft(const TYP *lpText, size_t iLen)
[代入] 文字数制限代入.
Definition: TnbStr.h:278
int Replace(TYP tOld, TYP tNew)
[処理] 文字置換.
Definition: TnbStr.h:1038
virtual size_t GetSize(void) const
[取得] サイズ取得
Definition: TnbVector.h:368
virtual bool SetSize(size_t size)
[操作] サイズ指定
Definition: TnbVector.h:618
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
Definition: TnbVector.h:383
virtual bool Set(INDEX index, const TYP &t)
[設定] 要素の設定.
Definition: TnbVector.h:265
virtual size_t SetElements(size_t size, const TYP *P=NULL)
[設定] 複数要素設定.
Definition: TnbVector.h:526
TNB::CVectorT< CAscii > CAsciiVector
文字列配列管理クラス
Definition: TnbStrVector.h:40
TNB::CVectorT< CUnicode > CUnicodeVector
文字列配列管理クラス
Definition: TnbStrVector.h:49
TNB::CVectorT< CString > CStringVector
CString配列管理クラス
Definition: TnbStrVector.h:283
TNB::CVectorT< CStr > CStrVector
文字列配列管理クラス
Definition: TnbStrVector.h:31
CStrVector ToStrVector(const CStringArray &astr)
[複製] CStringArrayから CStrVector へコピー
Definition: TnbStrVector.h:293
CStr StrVectorToStrEx(const CStrVector &vs, TCHAR sepaChar='^', TCHAR escChar='\\')
[変換] CStrVector → CStr
Definition: TnbStrVector.h:172
int GetCharSize(char c)
[取得] 文字のサイズ(ASCII/SJIS用)
Definition: TnbStrLib.h:341
INT_PTR IndexOf(LPCSTR lpszText, char c, INDEX iFromIndex=0)
[検索] 文字検索(ASCII/SJIS用)
Definition: TnbStrLib.h:184
size_t GetLen(LPCSTR lpsz)
[計算] 文字列長計算(ASCII/SJIS用)
Definition: TnbStrLib.h:44
CStr StrVectorToStr(const CStrVector &vs, TCHAR sepaChar='^')
[変換] CStrVector → CStr
Definition: TnbStrVector.h:114
CStrVector operator%(const CStr &s1, const CStr &s2)
[追加] 文字列追加特殊オペレータ.
Definition: TnbStrVector.h:245
CStrVector StrToStrVectorEx(LPCTSTR lpsz, TCHAR sepaChar='^', TCHAR escChar='\\')
[変換] CStr → CStrVector
Definition: TnbStrVector.h:201
CWordVector StringToWordVector(LPCSTR lpszAscii)
[変換] ASCII文字列→文字単位配列
Definition: TnbStrVector.h:63
TNB::CStrT< TCHAR > CStr
文字列クラス
Definition: TnbStr.h:1785
CStrVector StrToStrVector(LPCTSTR lpsz, TCHAR sepaChar='^')
[変換] CStr → CStrVector
Definition: TnbStrVector.h:138
TNB Library
Definition: TnbDoxyTitle.txt:2
void TRACE_SV(const CStrVector &vs)
[出力] デバッグトレース.
Definition: TnbStrVector.h:315