-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSplitter.cpp
More file actions
38 lines (34 loc) · 716 Bytes
/
Splitter.cpp
File metadata and controls
38 lines (34 loc) · 716 Bytes
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
#include "stdafx.h"
#include "Splitter.h"
CSplitter::CSplitter()
{
Init();
}
CSplitter::CSplitter(const CString isAlphaExceptions)
{
Init();
for (int i=0; i<isAlphaExceptions.GetLength(); i++)
isAlpha[isAlphaExceptions[i]] = 1;
m_isAlphaExceptions = isAlphaExceptions;
}
void CSplitter::Init()
{
// prepare cache array
for (int i=0; i<0xFFFF; i++)
isAlpha[i] = iswalpha(i) | iswdigit(i);
}
void CSplitter::Split(CString *src, CWords *words)
{
int j=0, size = src->GetLength();
words->RemoveAll();
for (int i=0; i<size; i++)
{
if (!isAlpha[src->GetAt(i)])
{
if (i-j) words->Add(j,src->Mid(j, i-j));
j=i+1;
}
// add last word
else if (i+1==size) words->Add(j,src->Mid(j, i-j+1));
}
}