-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringTools.h
More file actions
55 lines (45 loc) · 1.83 KB
/
StringTools.h
File metadata and controls
55 lines (45 loc) · 1.83 KB
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
//
// StringTools.h
// TankGame
//
// Created by Jacob Gonzalez on 11/04/2015.
// Copyright (c) 2015 Jacob Gonzalez. All rights reserved.
//
#ifndef _StringTools_H
#define _StringTools_H
#include "Point.h"
#include "MutableArray.h"
#include <stdlib.h>
#include <string>
typedef MutableArray<std::string> vstring;
// :: static utility class for string manipulation ::
class StringTools
{
public:
// : returns num lines in instring :
static int string_height(std::string instring);
// : returns num characters of top line :
static int string_width(std::string instring);
// : returns a point for height and width :
static Point<int> string_size(std::string instring);
// : read lines from a file into a vector :
static vstring readlines(std::string filename);
// : read all text file into string :
static std::string readall(std::string filename);
// : split a string into a parts by the a multichar delimeter :
static vstring split(std::string instring, std::string del);
// : split a string using multiple single delimeters :
static vstring tokens(std::string instring, std::string del);
// : methods for removing whitespace from start and end of strings :
static std::string ltrim(std::string instring, std::string whitespaces);
static std::string rtrim(std::string instring, std::string whitespaces);
static std::string trim(std::string instring);
static std::string trim(std::string instring, std::string whitespaces);
// : replace all occurances of <from> to <to> in <instring> :
static std::string replace_all(std::string instring,
std::string from,
std::string to);
private:
static void _recSplit(std::string instring, vstring &parts, std::string del, bool tokens);
};
#endif /* _StringTools_H */