|
/**
Copyright 2000 - 2003 LogicMatrix. All rights reserved.
This software is distributed under the LogicMatrix Free Software License. This software may be used for any purpose, personal or commercial. Redistributions in binary /source code form are permitted. Commercial redistribution of larger works derived from, or works which bundle this software requires a "Commercial Redistribution License" which can be purchased from LogicMatrix. Contact LogicMatrix for details
Redistributions qualify as Free and non-commercial under one of the following terms:
1) Redistributions are made at no charge beyond the reasonable cost of materials and delivery.
2) Redistributions in binary/source code form must reproduce this Copyright Notice,these license terms, and the disclaimer/limitation of liability set forth as below, in the documentation and/or other materials
provided with the distribution.
Disclaimer
==========
The Software is provided on an "AS IS" basis. No warranty is
provided that the Software is free of defects, or fit for a
particular purpose.
Limitation of Liability
=======================
LogicMatrix shall not be liable for any damages suffered by the Licensee or any third party resulting from use of the Software.
**/
/**
text.cpp
Purpose: Some text related functions
Author: Vijay Mathew Pandyalakal
Date: 14/11/2003
Copyright: logicmatrix
**/
#include <string>
using namespace std;
#include "text.h"
using namespace dsqlm;
string Text::trim(string s) {
string ret = "";
int len = s.length();
char* buff = new char[len + 1];
strcpy(buff,s.c_str());
bool found = false;
for(int i = 0;i<len;i++) {
char c = buff[i];
if(c == ' ') {
if(!found) {
continue;
}
}else {
found = true;
}
ret += c;
}
delete[] buff;
len = ret.length();
buff = new char[len+1];
found = false;
strcpy(buff,ret.c_str());
ret = "";
len--;
for(i = len;i>=0;i--) {
char c = buff[i];
if(c == ' ') {
if(!found) {
continue;
}
}else {
found = true;
}
ret += c;
}
delete[] buff;
len = ret.length();
buff = new char[len+1];
strcpy(buff,ret.c_str());
len--;
ret = "";
for(i=len;i>=0;i--) {
ret += buff[i];
}
delete[] buff;
return ret;
}
string Text::capitalize(string s) {
int len = s.size();
string ret = "";
bool up = false;
for(int i=0;i<len;i++) {
if(i == 0) {
ret += toupper(s[i]);
}else if(up) {
ret += toupper(s[i]);
up = false;
}else if(s[i] == ' ' || s[i] == '.') {
up = true;
ret += s[i];
}else {
ret += tolower(s[i]);
}
}
return ret;
}
string Text::uppercase(string s) {
int len = s.size();
string ret = "";
bool up = false;
for(int i=0;i<len;i++) {
ret += toupper(s[i]);
}
return ret;
}
string Text::lowercase(string s) {
int len = s.size();
string ret = "";
bool up = false;
for(int i=0;i<len;i++) {
ret += tolower(s[i]);
}
return ret;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.