helper.cpp
cowmud-0.11/src/helper.cpp · 1.1 KB
From the archive cowmud-0.11.tar.gz
Download the archive « Back to the archive contents
#include <string>
#include "defines.h"
void writeChar(Character & ch, string buf)
{
if (ch.getStatus() == STATUS_INGAME) {
ch.addWriteBuf(buf);
}
}
string stripCarriageReturn(string str)
{
for (uint count = 0; count < str.length(); count++) {
if (str[count] == '\n' || str[count] == '\r') {
str.erase(count, 1);
count--;
}
}
return str;
}
char makeLower(char c)
{
uint asciicode = (uint)c;
if (asciicode < 65 || asciicode > 90) {
return c;
}
return (char)(asciicode + 32);
}
char makeUpper(char c)
{
uint asciicode = (uint)c;
if (asciicode < 97 || asciicode > 122) {
return c;
}
return (char)(asciicode - 32);
}
string argument(string str, int n) {
uint pos = 0;
int count = 1;
if (n == 1) {
if (str.find(" ", 0) != string::npos) {
return str.substr(0, str.find(" ", 0));
} else {
return str;
}
}
while (pos != string::npos) {
if (count == n) {
return str.substr(pos + 1, str.find(" ", pos + 1));
}
pos = str.find(" ", pos + 1);
count++;
}
return "";
}