#include "StringOps.h"
#include <string>
#include <vector>
extern int UINTSIZE;
void split(const string &str, char c, vector<string> &output) {
int i = 0, last = -1, strlength = str.length();
for(i = 0; i < strlength; i++) {
if(str[i] == c) {
if(last != -1) {
output.push_back(str.substr(last, i - last));
}
last = -1;
}
else if(last == -1) {
last = i;
}
}
if(last != -1) {
output.push_back(str.substr(last, strlength - last));
}
}
void trim(string &str) {
unsigned int i = 0;
while(i < str.length() && str[i] == ' ') {
i++;
}
str.erase(0,i);
i = str.length() - 1;
while(i >= 0 && str[i] == ' ') {
i--;
}
str.erase(i + 1, str.length() - i + 1);
}
bool alphachar(char c) {
return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
}
void copyWord(byte *a, byte *b, unsigned int length) {
unsigned int i = 0;
for(i = 0; i < length; i++) {
a[i] = b[i];
}
}
void copyUIntArray(unsigned int *a, unsigned int *b, unsigned int length) {
unsigned int i = 0;
for(i = 0; i < length; i++) {
a[i] = b[i];
}
}
void printArray(byte *arr, unsigned int length) {
unsigned int i = 0;
for(i = 0; i < length; i++) {
cout << (int) arr[i];
if(i != length - 1)
cout << ",";
}
cout << "\n";
}
void printUInt(unsigned int word, unsigned int length) {
unsigned int i = 0;
for(i = 0; i < length; i++) {
if(word & (1 << i))
cout << "1";
else
cout << "0";
}
cout << "\n";
}
void printUIntArray(unsigned int word[], unsigned int length) {
unsigned int i = 0;
int j;
while(length > 0) {
for(j = 0; j < (UINTSIZE < (int)length ? UINTSIZE : (int)length); j++) {
if(word[i] & (1 << j))
cout << "1";
else
cout << "0";
}
cout << " ";
length -= UINTSIZE;
i++;
}
}
bool iterateWord(byte* arr, unsigned int length, unsigned int shiftSize) {
unsigned int i = 0;
bool ret = false;
while(i < length) {
arr[i]++;
if(arr[i] >= shiftSize) {
arr[i] = 0;
i++;
}
else
break;
}
if(i == length)
ret = true;
return ret;
}