-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.h
72 lines (61 loc) · 1.78 KB
/
Utils.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
70
71
72
//---------------------------------------------------------------------------
#ifndef UtilsH
#define UtilsH
#include <System.hpp>
#include <System.SysUtils.hpp>
#include <cstdint>
#include <memory>
#include <algorithm>
#include "RegexDefs.h"
//---------------------------------------------------------------------------
extern uint16_t ParseWord( String Text );
//---------------------------------------------------------------------------
template<typename C>
String WordsToString( C Data )
{
auto SB = std::make_unique<TStringBuilder>();
size_t n {};
for ( auto const & di : Data ) {
SB->AppendFormat(
n++ ? _T( ", %d" ) : _T( "%d" ), ARRAYOFCONST( ( di ) )
);
}
return SB->ToString();
}
//---------------------------------------------------------------------------
#if !defined( USE_STD_REGEX )
#if !defined(_UNICODE)
using cregex_iterator_type = boost::cregex_iterator;
#else
using cregex_iterator_type = boost::wcregex_iterator;
#endif
#else
#if !defined(_UNICODE)
using cregex_iterator_type = std::cregex_iterator;
#else
using cregex_iterator_type = std::wcregex_iterator;
#endif
#endif
template<typename OutIt>
int StringToSaturatedWords( String Text, OutIt Out )
{
int Cnt = 0;
regex_type re( _T( "(-?\\d+)[^\\d]\?" ) );
regex_cmatch_type m;
cregex_iterator_type m1( Text.c_str(), Text.c_str() + Text.Length(), re );
cregex_iterator_type m2;
for ( ; m1 != m2 ; m1++ ) {
int const Id =
std::min(
std::max( String( (*m1)[1].str().c_str() ).ToInt(), 0 ),
65535
);
*Out++ = Id;
if ( Id ) {
++Cnt;
}
}
return Cnt;
}
//---------------------------------------------------------------------------
#endif