2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 #include "Exception.h"
28 Split::Split(LPCWSTR sep
, CStringW str
, size_t limit
, SplitType type
)
30 DoSplit(sep
, str
, limit
, type
);
33 Split::Split(WCHAR sep
, CStringW str
, size_t limit
, SplitType type
)
35 DoSplit(CStringW(sep
), str
, limit
, type
);
38 void Split::DoSplit(LPCWSTR sep
, CStringW str
, size_t limit
, SplitType type
)
42 if(size_t seplen
= wcslen(sep
))
44 for(int i
= 0, j
= 0, len
= str
.GetLength();
45 i
<= len
&& (limit
== 0 || GetCount() < limit
);
51 CStringW s
= i
< j
? str
.Mid(i
, j
- i
) : L
"";
55 case Min
: s
.Trim(); // fall through
56 case Def
: if(s
.IsEmpty()) break; // else fall through
57 case Max
: Add(s
); break;
63 int Split::GetAtInt(size_t i
)
65 if(i
>= GetCount()) throw Exception(_T("Index out of bounds"));
66 return _wtoi(GetAt(i
));
69 float Split::GetAtFloat(size_t i
)
71 if(i
>= GetCount()) throw Exception(_T("Index out of bounds"));
72 return (float)_wtof(GetAt(i
));