-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.cpp
More file actions
64 lines (56 loc) · 1.07 KB
/
strings.cpp
File metadata and controls
64 lines (56 loc) · 1.07 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
56
57
58
59
60
61
62
63
64
#include "strings.h"
const std::string delim = "?!.;,*";
// convert a string to uppercase
void UpperCase( std::string &str )
{
int len = str.length();
for( int i = 0; i < len; i++ )
{
if ( str[i] >= 'a' && str[i] <= 'z' )
{
str[i] -= 'a' - 'A';
}
}
}
// verifies that a given
// character is a puntuation
bool isPunc(char c)
{
return delim.find(c) != std::string::npos;
}
// removes punctuation and redundant
// spaces from the user's input
void cleanString( std::string &str )
{
int len = str.length();
std::string temp = "";
char prevChar = 0;
for(int i = 0; i < len; ++i)
{
if( (str[i] == ' ' && prevChar != ' ') || !isPunc(str[i]) )
{
temp += str[i];
prevChar = str[i];
}
else if(prevChar != ' ' && isPunc(str[i]))
{
temp += ' ';
}
}
str = temp;
}
// copie the content of a string array to a vector
void copy(char *array[], vstring &v)
{
for(int i = 0; i < MAX_RESP; ++i)
{
if(array[i] != NULL)
{
v.push_back(array[i]);
}
else
{
break;
}
}
}