StringHelper.h Source File
Back to the index.
src
include
StringHelper.h
Go to the documentation of this file.
1
#ifndef STRINGHELPER_H
2
#define STRINGHELPER_H
3
4
/*
5
* Copyright (C) 2010 Anders Gavare. All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
*
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
* 3. The name of the author may not be used to endorse or promote products
16
* derived from this software without specific prior written permission.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
* SUCH DAMAGE.
29
*/
30
31
#include "
misc.h
"
32
33
#include "
UnitTest.h
"
34
35
36
/**
37
* \brief A helper class, with static functions for common string operations.
38
*/
39
class
StringHelper
40
:
public
UnitTestable
41
{
42
private
:
43
/**
44
* \brief No constructor.
45
*/
46
StringHelper
();
47
48
public
:
49
/**
50
* \brief Parses a string into a 64-bit number.
51
*
52
* @param str A pointer to a character string.
53
* @param error Set to false if a parsed value is returned, true on
54
* parse errors.
55
* @return A uint64_t, representing the parsed value.
56
*/
57
static
uint64_t
ParseNumber
(
const
char
* str,
bool
& error);
58
59
/**
60
* \brief Splits a string with a certain delimiter into a vector of strings.
61
*
62
* E.g. if the input string is "A:B:C" and the splitter is ':', then
63
* the resulting vector consists of 3 strings: "A", "B", and "C".
64
*
65
* NOTE: The current implementation is very slow, but it at least it works.
66
*
67
* @param str A string to split.
68
* @param splitter Set to false if a parsed value is returned, true on
69
* parse errors.
70
* @return A vector of strings (without the splitter char).
71
*/
72
static
vector<string>
SplitStringIntoVector
(
const
string
&str,
const
char
splitter);
73
74
/********************************************************************/
75
76
static
void
RunUnitTests
(
int
& nSucceeded,
int
& nFailures);
77
};
78
79
80
#endif // STRINGHELPER_H
StringHelper::SplitStringIntoVector
static vector< string > SplitStringIntoVector(const string &str, const char splitter)
Splits a string with a certain delimiter into a vector of strings.
Definition:
StringHelper.cc:99
misc.h
StringHelper
A helper class, with static functions for common string operations.
Definition:
StringHelper.h:39
UnitTest.h
UnitTestable
Base class for unit testable classes.
Definition:
UnitTest.h:74
StringHelper::RunUnitTests
static void RunUnitTests(int &nSucceeded, int &nFailures)
StringHelper::ParseNumber
static uint64_t ParseNumber(const char *str, bool &error)
Parses a string into a 64-bit number.
Definition:
StringHelper.cc:34
Generated on Tue Mar 24 2020 14:04:48 for GXemul by
1.8.17