// -*-c++-*- //------------------------------------------------------------------------------ // xword - (http://xword.sourceforge.net) // Copyright 2002 Patrick Crosby //------------------------------------------------------------------------------ // String.cpp // // $Id: String.cpp,v 1.3 2002/01/23 19:43:03 pcrosby Exp $ //------------------------------------------------------------------------------ // This program is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free Software // Foundation; either version 2 of the License, or (at your option) any later // version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // details. // // You should have received a copy of the GNU General Public License along with // this program; if not, write to the Free Software Foundation, Inc., 59 Temple // Place, Suite 330, Boston, MA 02111-1307 USA //------------------------------------------------------------------------------ #include "String.h" #include #include #include "Namespace.h" NAMESPACE_OPEN //------------------------------------------------------------------------------ String::String(int n) : std::string() { if (n < 0) { #ifdef HAVE_STRING_PUSH_BACK push_back('-'); #else append("-"); #endif n = -n; } Convert(n); } //------------------------------------------------------------------------------ std::string String::Upper(const std::string& strIn) { std::string strResult; #ifdef HAVE_STRING_PUSH_BACK // uppercase all characters transform(strIn.begin(), strIn.end(), back_inserter(strResult), toupper); #endif return strResult; } //------------------------------------------------------------------------------ std::string String::Lower(const std::string& strIn) { std::string strResult; #ifdef HAVE_STRING_PUSH_BACK // lowercase all characters transform(strIn.begin(), strIn.end(), back_inserter(strResult), tolower); #endif return strResult; } //------------------------------------------------------------------------------ void String::Convert(int n) { if (n < 10) { #ifdef HAVE_STRING_PUSH_BACK push_back(n + '0'); #else char s[2]; s[0] = n + '0'; s[1] = '\0'; append(s); #endif return; } int nRemainder = n % 10; Convert((n - nRemainder) / 10); #ifdef HAVE_STRING_PUSH_BACK push_back(nRemainder + '0'); #else char sr[2]; sr[0] = nRemainder + '0'; sr[1] = '\0'; append(sr); #endif } //------------------------------------------------------------------------------ NAMESPACE_CLOSE //------------------------------------------------------------------------------