-
Notifications
You must be signed in to change notification settings - Fork 2
/
StrUtils.h
69 lines (62 loc) · 1.67 KB
/
StrUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <atlstr.h>
#include <atlcoll.h>
inline int StrRevFind(LPCTSTR lpStr, TCHAR c)
{
for (int i = lstrlen(lpStr) - 1; i >= 0; i--)
{
if (lpStr[i] == c)
{
return i;
}
}
return -1;
}
inline void SplitString(const CString& strInputString, const CString& strDelimiter, CAtlArray<CString>& arrStringArray)
{
const int sizeS2 = strDelimiter.GetLength();
const int isize = strInputString.GetLength();
int newPos = strInputString.Find(strDelimiter, 0);
//if (newPos < 0)
//return;
CAtlArray<INT> positions;
int iPos = 0;
while (newPos > iPos)
{
positions.Add(newPos);
iPos = newPos;
newPos = strInputString.Find(strDelimiter, iPos + sizeS2);
}
for (int i = 0; i <= positions.GetCount(); i++)
{
CString s;
if (i == 0)
{
if (i == positions.GetCount())
s = strInputString;
else
s = strInputString.Mid(i, positions[i]);
}
else
{
int offset = positions[i - 1] + sizeS2;
if (offset < isize)
{
if (i == positions.GetCount())
s = strInputString.Mid(offset);
else
s = strInputString.Mid(positions[i - 1] + sizeS2, positions[i] - positions[i - 1] - sizeS2);
}
}
arrStringArray.Add(s);
}
}
inline size_t Find(const CAtlArray<CString>& arrStringArray, const CString& strFind)
{
for (size_t i = 0; i < arrStringArray.GetCount(); ++i)
{
if (arrStringArray[i] == strFind)
return i;
}
return SIZE_T_MAX;
}