forked from guozanhua/FTL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StrCount.h
49 lines (38 loc) · 840 Bytes
/
StrCount.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
/*
* Copyright 2010-2015 Fabric Software Inc. All rights reserved.
*/
#ifndef _FTL_StrCount_h
#define _FTL_StrCount_h
#include <FTL/Config.h>
#include <FTL/MatchCharSingle.h>
#include <string>
FTL_NAMESPACE_BEGIN
template<typename MatchChar>
size_t StrCount( char const *cStr )
{
MatchChar const fn;
size_t count = 0;
while ( *cStr )
{
if ( fn( *cStr++ ) )
++count;
}
return count;
}
template<typename MatchChar>
size_t StrCount( std::string const &str )
{
return StrCount<MatchChar>( str.c_str() );
}
template<char CharToMatch>
size_t StrCount( char const *cStr )
{
return StrCount< MatchCharSingle<CharToMatch> >( cStr );
}
template<char CharToMatch>
size_t StrCount( std::string const &str )
{
return StrCount< MatchCharSingle<CharToMatch> >( str );
}
FTL_NAMESPACE_END
#endif //_FTL_StrCount_h