From 6ab3bc95b223565612d589b74b77ac7a3f4925cc Mon Sep 17 00:00:00 2001 From: Reinhard Pfau Date: Mon, 7 Apr 2008 14:30:13 +0000 Subject: [PATCH] libi2ncommon: (reinhard) modified stringfunc (and some others) according to our new style guide. --- src/daemonfunc.cpp | 2 +- src/filefunc.cpp | 26 +- src/stringfunc.cpp | 1300 +++++++++++++++++++++++++++------------------------- src/stringfunc.hxx | 130 +++--- 4 files changed, 748 insertions(+), 710 deletions(-) diff --git a/src/daemonfunc.cpp b/src/daemonfunc.cpp index 5f874ef..43a4750 100644 --- a/src/daemonfunc.cpp +++ b/src/daemonfunc.cpp @@ -91,7 +91,7 @@ bool pid_of(const std::string& name, std::vector< pid_t >& result) ++it) { pid_t pid; - if (! stringTo(*it, pid)) continue; + if (! string_to(*it, pid)) continue; std::string base_path= std::string("/proc/") + *it; std::string exe_path= base_path + "/exe"; I2n::Stat stat(exe_path, false); diff --git a/src/filefunc.cpp b/src/filefunc.cpp index a37d0ae..a00c3fe 100644 --- a/src/filefunc.cpp +++ b/src/filefunc.cpp @@ -25,8 +25,6 @@ #include "filefunc.hxx" #include "stringfunc.hxx" -// TODO: Remove me once libi2ncommon is completly switched to I2n -using namespace i2n; namespace I2n { @@ -101,7 +99,7 @@ void Stat::stat(const std::string& path, bool follow_links) IsRegular= S_ISREG( stat_info.st_mode ); IsDirectory= S_ISDIR( stat_info.st_mode ); IsCharacterDevice= S_ISCHR( stat_info.st_mode ); - IsBlockDevice= S_ISBLK( stat_info.st_mode ); + IsBlockDevice= S_ISBLK( stat_info.st_mode ); IsFifo= S_ISFIFO( stat_info.st_mode ); IsSocket= S_ISSOCK( stat_info.st_mode ); } @@ -232,7 +230,7 @@ time_t file_mtime(const std::string& path) int res = ::stat(path.c_str(), &stat_info); if (res) return 0; return stat_info.st_mtime; -} // eo fileMTime(const std::string&) +} // eo file_mtime(const std::string&) /** @@ -264,7 +262,7 @@ bool get_dir( } ::closedir(dir); return true; -} // eo getDir(const std::string&,std::vector< std::string >&,bool) +} // eo get_dir(const std::string&,std::vector< std::string >&,bool) /** @@ -278,7 +276,7 @@ std::vector< std::string > get_dir(const std::string& path, bool include_dot_nam std::vector< std::string > result; get_dir(path,result,include_dot_names); return result; -} // eo getDir(const std::string&,bool) +} // eo get_dir(const std::string&,bool) @@ -375,7 +373,7 @@ std::string read_link(const std::string& path) return std::string( buffer_ptr.get(), res ); } return std::string(); -} // eo readLink(const std::string&) +} // eo read_link(const std::string&) @@ -416,7 +414,7 @@ std::string read_file(const std::string& path) } } return result; -} // eo readFile +} // eo read_file(const std::string&) /** @@ -439,7 +437,7 @@ bool write_file(const std::string& path, const std::string& data) { return false; } -} // eo writeFile +} // eo write_file(const std::string&,const std::string&) /** @@ -503,7 +501,7 @@ std::string normalize_path(const std::string& path) std::list< std::string > parts; std::list< std::string > result_parts; - splitString(path,parts,"/",true); + split_string(path,parts,"/",true); for(std::list< std::string >::const_iterator it_parts= parts.begin(); it_parts != parts.end(); @@ -550,9 +548,9 @@ std::string normalize_path(const std::string& path) { result= "/"; } - result+= joinString(result_parts,"/"); + result+= join_string(result_parts,"/"); return result; -} // eo normalizePath(const std::string&) +} // eo normalize_path(const std::string&) /** @@ -652,6 +650,6 @@ bool recursive_delete(const std::string &path, std::string *error) } return rtn; -} +} // eo recursive_delete(const std::string&,std::string*) -} +} // eo namespace I2n diff --git a/src/stringfunc.cpp b/src/stringfunc.cpp index 7bf16f9..98fe5e1 100644 --- a/src/stringfunc.cpp +++ b/src/stringfunc.cpp @@ -1,7 +1,7 @@ /** @file * * (c) Copyright 2007-2008 by Intra2net AG - * + * * info@intra2net.com */ @@ -19,10 +19,12 @@ using namespace std; -namespace i2n { +namespace I2n +{ -namespace { +namespace +{ const std::string hexDigitsLower("0123456789abcdef"); const std::string hexDigitsUpper("0123456789ABCDEF"); @@ -30,19 +32,19 @@ const std::string hexDigitsUpper("0123456789ABCDEF"); struct UpperFunc { - char operator() (char c) - { - return std::toupper(c); - } + char operator() (char c) + { + return std::toupper(c); + } }; // eo struct UpperFunc struct LowerFunc { - char operator() (char c) - { - return std::tolower(c); - } + char operator() (char c) + { + return std::tolower(c); + } }; // eo struct LowerFunc @@ -51,14 +53,14 @@ struct LowerFunc /** - * default list of whitespaces (" \t\r\n"); + * default list of Whitespaces (" \t\r\n"); */ -const std::string whitespaces = " \t\r\n"; +const std::string Whitespaces = " \t\r\n"; /** * default list of lineendings ("\r\n"); */ -const std::string lineends= "\r\n"; +const std::string LineEndings= "\r\n"; @@ -68,14 +70,14 @@ const std::string lineends= "\r\n"; * @param prefix the prefix which should be tested for. * @return @a true iff the prefix is not empty and the string begins with that prefix. */ -bool hasPrefix(const std::string& str, const std::string& prefix) +bool has_prefix(const std::string& str, const std::string& prefix) { - if (prefix.empty() || str.empty() || str.size() < prefix.size()) - { - return false; - } - return str.compare(0, prefix.size(), prefix) == 0; -} // eo hasPrefix(const std::string&,const std::string&) + if (prefix.empty() || str.empty() || str.size() < prefix.size() ) + { + return false; + } + return str.compare(0, prefix.size(), prefix) == 0; +} // eo has_prefix(const std::string&,const std::string&) /** @@ -84,14 +86,14 @@ bool hasPrefix(const std::string& str, const std::string& prefix) * @param suffix the suffix which should be tested for. * @return @a true iff the suffix is not empty and the string ends with that suffix. */ -bool hasSuffix(const std::string& str, const std::string& suffix) +bool has_suffix(const std::string& str, const std::string& suffix) { - if (suffix.empty() || str.empty() || str.size() < suffix.size()) - { - return false; - } - return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; -} // eo hasSuffix(const std::string&,const std::string&) + if (suffix.empty() || str.empty() || str.size() < suffix.size() ) + { + return false; + } + return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; +} // eo has_suffix(const std::string&,const std::string&) /** @@ -100,29 +102,29 @@ bool hasSuffix(const std::string& str, const std::string& suffix) * @param charlist the list of characters to remove from beginning and end of string * @return the result string. */ -std::string trimMod(std::string& str, const std::string& charlist) -{ - // first: trim the beginning: - std::string::size_type pos= str.find_first_not_of(charlist); - if (pos == std::string::npos) - { - // whole string consists of charlist (or is already empty) - str.clear(); - return str; - } - else if (pos>0) - { - // str starts with charlist - str.erase(0,pos); - } - // now let's look at the tail: - pos= str.find_last_not_of(charlist)+1; // note: we already know there is at least one other char! - if ( pos < str.size() ) - { - str.erase(pos, str.size()-pos); - } - return str; -} // eo trimMod(std::string&,const std::string&) +std::string trim_mod(std::string& str, const std::string& charlist) +{ + // first: trim the beginning: + std::string::size_type pos= str.find_first_not_of (charlist); + if (pos == std::string::npos) + { + // whole string consists of charlist (or is already empty) + str.clear(); + return str; + } + else if (pos>0) + { + // str starts with charlist + str.erase(0,pos); + } + // now let's look at the tail: + pos= str.find_last_not_of(charlist) +1; // note: we already know there is at least one other char! + if ( pos < str.size() ) + { + str.erase(pos, str.size()-pos); + } + return str; +} // eo trim_mod(std::string&,const std::string&) @@ -132,18 +134,18 @@ std::string trimMod(std::string& str, const std::string& charlist) * @param what the list of chars which will be tested for. * @return the resulting string with last char removed (if applicable) */ -std::string chompMod(std::string& str, const std::string& what) +std::string chomp_mod(std::string& str, const std::string& what) { - if (str.empty() || what.empty()) - { - return str; - } - if (what.find( str.at(str.size()-1) ) != std::string::npos) - { - str.erase( str.size() - 1); - } - return str; -} // eo chompMod(std::string&,const std::string&) + if (str.empty() || what.empty() ) + { + return str; + } + if (what.find(str.at (str.size()-1) ) != std::string::npos) + { + str.erase(str.size() - 1); + } + return str; +} // eo chomp_mod(std::string&,const std::string&) /** @@ -151,11 +153,11 @@ std::string chompMod(std::string& str, const std::string& what) * @param[in,out] str the string to modify. * @return the string */ -std::string lowerMod(std::string& str) +std::string to_lower_mod(std::string& str) { - std::transform( str.begin(), str.end(), str.begin(), LowerFunc() ); - return str; -} // eo lowerMod(std::string&) + std::transform(str.begin(), str.end(), str.begin(), LowerFunc() ); + return str; +} // eo to_lower_mod(std::string&) /** @@ -163,11 +165,11 @@ std::string lowerMod(std::string& str) * @param[in,out] str the string to modify. * @return the string */ -std::string upperMod(std::string& str) +std::string to_upper_mod(std::string& str) { - std::transform( str.begin(), str.end(), str.begin(), UpperFunc() ); - return str; -} // eo upperMod(std::string&) + std::transform( str.begin(), str.end(), str.begin(), UpperFunc() ); + return str; +} // eo to_upper_mod(std::string&) @@ -177,18 +179,18 @@ std::string upperMod(std::string& str) * @param charlist the list of characters to remove from beginning and end of string * @return the result string. */ -std::string trim(const std::string& str, const std::string& charlist) -{ - // first: trim the beginning: - std::string::size_type pos0= str.find_first_not_of(charlist); - if (pos0 == std::string::npos) - { - // whole string consists of charlist (or is already empty) - return std::string(); - } - // now let's look at the end: - std::string::size_type pos1= str.find_last_not_of(charlist); - return str.substr(pos0, pos1 - pos0 + 1); +std::string trim (const std::string& str, const std::string& charlist) +{ + // first: trim the beginning: + std::string::size_type pos0= str.find_first_not_of(charlist); + if (pos0 == std::string::npos) + { + // whole string consists of charlist (or is already empty) + return std::string(); + } + // now let's look at the end: + std::string::size_type pos1= str.find_last_not_of(charlist); + return str.substr(pos0, pos1 - pos0 + 1); } // eo trim(const std:.string&,const std::string&) @@ -198,17 +200,17 @@ std::string trim(const std::string& str, const std::string& charlist) * @param what the list of chars which will be tested for. * @return the resulting string with last char removed (if applicable) */ -std::string chomp(const std::string& str, const std::string& what) -{ - if (str.empty() || what.empty()) - { - return str; - } - if (what.find( str.at(str.size()-1) ) != std::string::npos) - { - return str.substr(0, str.size()-1); - } - return str; +std::string chomp (const std::string& str, const std::string& what) +{ + if (str.empty() || what.empty() ) + { + return str; + } + if (what.find(str.at (str.size()-1) ) != std::string::npos) + { + return str.substr(0, str.size()-1); + } + return str; } // eo chomp(const std:.string&,const std::string&) @@ -217,11 +219,11 @@ std::string chomp(const std::string& str, const std::string& what) * @param str the string * @return the lower case version of the string */ -std::string lower(const std::string& str) +std::string to_lower (const std::string& str) { - std::string result(str); - return lowerMod(result); -} // eo lower(const std::string&) + std::string result(str); + return to_lower_mod(result); +} // eo to_lower(const std::string&) /** @@ -229,11 +231,11 @@ std::string lower(const std::string& str) * @param str the string * @return the upper case version of the string */ -std::string upper(const std::string& str) +std::string to_upper(const std::string& str) { - std::string result(str); - return upperMod(result); -} // eo upper(const std::string&) + std::string result(str); + return to_upper_mod(result); +} // eo to_upper(const std::string&) @@ -246,14 +248,14 @@ std::string upper(const std::string& str) * If the string ends with the suffix, it is removed. If the the string doesn't end * with the suffix the original string is returned. */ -std::string removeSuffix(const std::string& str, const std::string& suffix) +std::string remove_suffix(const std::string& str, const std::string& suffix) { - if (hasSuffix(str,suffix)) - { - return str.substr(0, str.size()-suffix.size() ); - } - return str; -} // eo removeSuffix(const std::string&,const std::string&) + if (has_suffix(str,suffix) ) + { + return str.substr(0, str.size()-suffix.size() ); + } + return str; +} // eo remove_suffix(const std::string&,const std::string&) @@ -266,39 +268,39 @@ std::string removeSuffix(const std::string& str, const std::string& suffix) * If the string begins with the prefix, it is removed. If the the string doesn't begin * with the prefix the original string is returned. */ -std::string removePrefix(const std::string& str, const std::string& prefix) +std::string remove_prefix(const std::string& str, const std::string& prefix) { - if (hasPrefix(str,prefix)) - { - return str.substr( prefix.size() ); - } - return str; -} // eo removePrefix(const std::string&,const std::string&) + if (has_prefix(str,prefix) ) + { + return str.substr( prefix.size() ); + } + return str; +} // eo remove_prefix(const std::string&,const std::string&) /** * split a string to key and value delimited by a given delimiter. - * The resulting key and value strings are trimmed (whitespaces removed at beginning and end). + * The resulting key and value strings are trimmed (Whitespaces removed at beginning and end). * @param str the string which should be splitted. * @param[out] key the resulting key * @param[out] value the resulting value * @param delimiter the delimiter between key and value; default is '='. * @return @a true if the split was successful. */ -bool pairSplit( - const std::string& str, - std::string& key, - std::string& value, - char delimiter) -{ - std::string::size_type pos = str.find(delimiter); - if (pos == std::string::npos) return false; - key= str.substr(0,pos); - value= str.substr(pos+1); - trimMod(key); - trimMod(value); - return true; -} // eo pairSplit(const std::string&,std::string&,std::string&,char) +bool pair_split( + const std::string& str, + std::string& key, + std::string& value, + char delimiter) +{ + std::string::size_type pos = str.find (delimiter); + if (pos == std::string::npos) return false; + key= str.substr(0,pos); + value= str.substr(pos+1); + trim_mod(key); + trim_mod(value); + return true; +} // eo pair_split(const std::string&,std::string&,std::string&,char) /** @@ -311,50 +313,50 @@ bool pairSplit( * @param[in] trim_list list of characters the parts should be trimmed by. * (empty string results in no trim) */ -void splitString( - const std::string& str, - std::list& result, - const std::string& delimiter, - bool omit_empty, - const std::string& trim_list +void split_string( + const std::string& str, + std::list& result, + const std::string& delimiter, + bool omit_empty, + const std::string& trim_list ) { - std::string::size_type pos, last_pos=0; - bool delimiter_found= false; - while ( last_pos < str.size() && last_pos != std::string::npos) - { - pos= str.find(delimiter, last_pos); - std::string part; - if (pos == std::string::npos) - { - part= str.substr(last_pos); - delimiter_found= false; - } - else - { - part= str.substr(last_pos, pos-last_pos); - delimiter_found=true; - } - if (pos != std::string::npos) - { - last_pos= pos+ delimiter.size(); - } - else - { - last_pos= std::string::npos; - } - if (!trim_list.empty()) trimMod(part, trim_list); - if (omit_empty && part.empty()) continue; - result.push_back( part ); - } - // if the string ends with a delimiter we need to append an empty string if no omit_empty - // was given. - // (this way we keep the split result consistent to a join operation) - if (delimiter_found && !omit_empty) - { - result.push_back(""); - } -} // eo splitString(const std::string&,std::list< std::string >&,const std::string&,bool,const std::string&) + std::string::size_type pos, last_pos=0; + bool delimiter_found= false; + while ( last_pos < str.size() && last_pos != std::string::npos) + { + pos= str.find(delimiter, last_pos); + std::string part; + if (pos == std::string::npos) + { + part= str.substr(last_pos); + delimiter_found= false; + } + else + { + part= str.substr(last_pos, pos-last_pos); + delimiter_found=true; + } + if (pos != std::string::npos) + { + last_pos= pos+ delimiter.size(); + } + else + { + last_pos= std::string::npos; + } + if (!trim_list.empty() ) trim_mod (part, trim_list); + if (omit_empty && part.empty() ) continue; + result.push_back( part ); + } + // if the string ends with a delimiter we need to append an empty string if no omit_empty + // was given. + // (this way we keep the split result consistent to a join operation) + if (delimiter_found && !omit_empty) + { + result.push_back(""); + } +} // eo split_string(const std::string&,std::list< std::string >&,const std::string&,bool,const std::string&) /** @@ -366,46 +368,46 @@ void splitString( * (empty string results in no trim) * @return the list resulting from splitting @a str. */ -std::list splitString( - const std::string& str, - const std::string& delimiter, - bool omit_empty, - const std::string& trim_list +std::list split_string( + const std::string& str, + const std::string& delimiter, + bool omit_empty, + const std::string& trim_list ) { - std::list result; - splitString(str, result, delimiter, omit_empty, trim_list); - return result; -} // eo splitString(const std::string&,const std::string&,bool,const std::string&) + std::list result; + split_string(str, result, delimiter, omit_empty, trim_list); + return result; +} // eo split_string(const std::string&,const std::string&,bool,const std::string&) /** * @brief joins a list of strings into a single string. * - * This funtion is (basically) the reverse operation of @a splitString. - * + * This funtion is (basically) the reverse operation of @a split_string. + * * @param parts the list of strings. * @param delimiter the delimiter which is inserted between the strings. * @return the joined string. */ -std::string joinString( - const std::list< std::string >& parts, - const std::string& delimiter +std::string join_string( + const std::list< std::string >& parts, + const std::string& delimiter ) { - std::string result; - if (! parts.empty()) - { - std::list< std::string >::const_iterator it= parts.begin(); - result = *it; - while( ++it != parts.end() ) - { - result+= delimiter; - result+= *it; - } - } - return result; -} // eo joinString(const std::list< std::string >&,const std::string&) + std::string result; + if (! parts.empty() ) + { + std::list< std::string >::const_iterator it= parts.begin(); + result = *it; + while ( ++it != parts.end() ) + { + result+= delimiter; + result+= *it; + } + } + return result; +} // eo join_string(const std::list< std::string >&,const std::string&) @@ -420,22 +422,22 @@ std::string joinString( * @param upper_case_digits determine whether to use upper case characters for digits A-F. * @return the string in hex notation. */ -std::string binaryToHex( - const std::string& str, - bool upper_case_digits +std::string convert_binary_to_hex( + const std::string& str, + bool upper_case_digits ) { - std::string result; - std::string hexDigits( upper_case_digits ? hexDigitsUpper : hexDigitsLower); - for(std::string::const_iterator it= str.begin(); - it != str.end(); - ++it) - { - result.push_back( hexDigits[ ((*it) >> 4) & 0x0f ] ); - result.push_back( hexDigits[ (*it) & 0x0f ] ); - } - return result; -} // eo binaryToHex(const std::string&,bool) + std::string result; + std::string hexDigits(upper_case_digits ? hexDigitsUpper : hexDigitsLower); + for ( std::string::const_iterator it= str.begin(); + it != str.end(); + ++it) + { + result.push_back( hexDigits[ ( (*it) >> 4) & 0x0f ] ); + result.push_back( hexDigits[ (*it) & 0x0f ] ); + } + return result; +} // eo convert_binary_to_hex(const std::string&,bool) /** @@ -448,568 +450,602 @@ std::string binaryToHex( * * @todo rework the handling of half nibbles (consistency)! */ -std::string hexToBinary( - const std::string& str +std::string convert_hex_to_binary( + const std::string& str ) -throw(std::runtime_error) -{ - std::string result; - char c= 0; - bool hasNibble= false; - bool lastWasWS= true; - for(std::string::const_iterator it= str.begin(); - it != str.end(); - ++it) - { - std::string::size_type p = hexDigitsLower.find( *it ); - if (p== std::string::npos) - { - p= hexDigitsUpper.find( *it ); - } - if (p == std::string::npos) - { - if ( ( whitespaces.find( *it ) != std::string::npos) // is it a whitespace? +throw (std::runtime_error) +{ + std::string result; + char c= 0; + bool hasNibble= false; + bool lastWasWS= true; + for ( std::string::const_iterator it= str.begin(); + it != str.end(); + ++it) + { + std::string::size_type p = hexDigitsLower.find( *it ); + if (p== std::string::npos) + { + p= hexDigitsUpper.find( *it ); + } + if (p == std::string::npos) + { + if ( ( Whitespaces.find( *it ) != std::string::npos) // is it a whitespace? or ( *it == ':') // or a colon? - ) + ) + { + // we treat that as a valid delimiter: + if (hasNibble) { - // we treat that as a valid delimiter: - if (hasNibble) - { - // 1 nibble before WS is treate as lower part: - result.push_back(c); - // reset state: - hasNibble= false; - } - lastWasWS= true; - continue; + // 1 nibble before WS is treate as lower part: + result.push_back(c); + // reset state: + hasNibble= false; } - } - if (p == std::string::npos ) - { - throw runtime_error("illegal character in hex digit string: " + str); - } - lastWasWS= false; - if (hasNibble) - { - c<<=4; - } - else - { - c=0; - } - c+= (p & 0x0f); - if (hasNibble) - { - //we already had a nibble, so a char is complete now: - result.push_back( c ); - hasNibble=false; - } - else - { - // this is the first nibble of a new char: - hasNibble=true; - } - } - if (hasNibble) - { - //well, there is one nibble left - // let's do some heuristics: - if (lastWasWS) - { - // if the preceeding character was a white space (or a colon) - // we treat the nibble as lower part: - //( this is consistent with shortened hex notations where leading zeros are not noted) - result.push_back( c ); - } - else - { - // if it was part of a hex digit chain, we treat it as UPPER part (!!) - result.push_back( c << 4 ); - } - } - return result; -} // eo hexToBinary(const std::string&) - - -} // eo namespace i2n + lastWasWS= true; + continue; + } + } + if (p == std::string::npos ) + { + throw runtime_error("illegal character in hex digit string: " + str); + } + lastWasWS= false; + if (hasNibble) + { + c<<=4; + } + else + { + c=0; + } + c+= (p & 0x0f); + if (hasNibble) + { + //we already had a nibble, so a char is complete now: + result.push_back( c ); + hasNibble=false; + } + else + { + // this is the first nibble of a new char: + hasNibble=true; + } + } + if (hasNibble) + { + //well, there is one nibble left + // let's do some heuristics: + if (lastWasWS) + { + // if the preceeding character was a white space (or a colon) + // we treat the nibble as lower part: + //( this is consistent with shortened hex notations where leading zeros are not noted) + result.push_back( c ); + } + else + { + // if it was part of a hex digit chain, we treat it as UPPER part (!!) + result.push_back( c << 4 ); + } + } + return result; +} // eo convert_hex_to_binary(const std::string&) + + +} // eo namespace I2n + + + std::string iso_to_utf8(const std::string& isostring) { - string result; + string result; - iconv_t i2utf8 = iconv_open ("UTF-8", "ISO-8859-1"); + iconv_t i2utf8 = iconv_open("UTF-8", "ISO-8859-1"); - if (iso_to_utf8 == (iconv_t)-1) - throw runtime_error("iconv can't convert from ISO-8859-1 to UTF-8"); + if (iso_to_utf8 == (iconv_t)-1) + throw runtime_error("iconv can't convert from ISO-8859-1 to UTF-8"); - size_t in_size=isostring.size(); - size_t out_size=in_size*4; + size_t in_size=isostring.size(); + size_t out_size=in_size*4; - char *buf = (char *)malloc(out_size+1); - if (buf == NULL) - throw runtime_error("out of memory for iconv buffer"); + char *buf = (char *)malloc(out_size+1); + if (buf == NULL) + throw runtime_error("out of memory for iconv buffer"); - const char *in = isostring.c_str(); - char *out = buf; - iconv (i2utf8, &in, &in_size, &out, &out_size); + const char *in = isostring.c_str(); + char *out = buf; + iconv(i2utf8, &in, &in_size, &out, &out_size); - buf[isostring.size()*4-out_size]=0; + buf[isostring.size()*4-out_size]=0; - result=buf; + result=buf; - free(buf); - iconv_close (i2utf8); + free(buf); + iconv_close(i2utf8); - return result; + return result; } std::string utf8_to_iso(const std::string& utf8string) { - string result; + string result; - iconv_t utf82iso = iconv_open ("ISO-8859-1","UTF-8"); + iconv_t utf82iso = iconv_open("ISO-8859-1","UTF-8"); - if (utf82iso == (iconv_t)-1) - throw runtime_error("iconv can't convert from UTF-8 to ISO-8859-1"); + if (utf82iso == (iconv_t)-1) + throw runtime_error("iconv can't convert from UTF-8 to ISO-8859-1"); - size_t in_size=utf8string.size(); - size_t out_size=in_size; + size_t in_size=utf8string.size(); + size_t out_size=in_size; - char *buf = (char *)malloc(out_size+1); - if (buf == NULL) - throw runtime_error("out of memory for iconv buffer"); + char *buf = (char *)malloc(out_size+1); + if (buf == NULL) + throw runtime_error("out of memory for iconv buffer"); - const char *in = utf8string.c_str(); - char *out = buf; - iconv (utf82iso, &in, &in_size, &out, &out_size); + const char *in = utf8string.c_str(); + char *out = buf; + iconv(utf82iso, &in, &in_size, &out, &out_size); - buf[utf8string.size()-out_size]=0; + buf[utf8string.size()-out_size]=0; - result=buf; + result=buf; - free(buf); - iconv_close (utf82iso); + free(buf); + iconv_close(utf82iso); - return result; + return result; } wchar_t* utf8_to_wbuf(const std::string& utf8string) { - iconv_t utf82wstr = iconv_open ("UCS-4LE","UTF-8"); + iconv_t utf82wstr = iconv_open("UCS-4LE","UTF-8"); - if (utf82wstr == (iconv_t)-1) - throw runtime_error("iconv can't convert from UTF-8 to UCS-4"); + if (utf82wstr == (iconv_t)-1) + throw runtime_error("iconv can't convert from UTF-8 to UCS-4"); - size_t in_size=utf8string.size(); - size_t out_size=(in_size+1)*sizeof(wchar_t); + size_t in_size=utf8string.size(); + size_t out_size= (in_size+1)*sizeof(wchar_t); - wchar_t *buf = (wchar_t *)malloc(out_size); - if (buf == NULL) - throw runtime_error("out of memory for iconv buffer"); + wchar_t *buf = (wchar_t *)malloc(out_size); + if (buf == NULL) + throw runtime_error("out of memory for iconv buffer"); - const char *in = utf8string.c_str(); - char *out = (char*)buf; - if (iconv (utf82wstr, &in, &in_size, &out, &out_size) == -1) - throw runtime_error("error converting char encodings"); + const char *in = utf8string.c_str(); + char *out = (char*) buf; + if (iconv(utf82wstr, &in, &in_size, &out, &out_size) == -1) + throw runtime_error("error converting char encodings"); - buf[((utf8string.size()+1)*sizeof(wchar_t)-out_size)/sizeof(wchar_t)]=0; + buf[ ( (utf8string.size()+1)*sizeof(wchar_t)-out_size) /sizeof(wchar_t) ]=0; - iconv_close (utf82wstr); + iconv_close(utf82wstr); - return buf; + return buf; } std::string utf7imap_to_utf8(const std::string& utf7imapstring) { - string result; + string result; - iconv_t utf7imap2utf8 = iconv_open ("UTF-8","UTF-7-IMAP"); + iconv_t utf7imap2utf8 = iconv_open("UTF-8","UTF-7-IMAP"); - if (utf7imap2utf8 == (iconv_t)-1) - throw runtime_error("iconv can't convert from UTF-7-IMAP to UTF-8"); + if (utf7imap2utf8 == (iconv_t)-1) + throw runtime_error("iconv can't convert from UTF-7-IMAP to UTF-8"); - size_t in_size=utf7imapstring.size(); - size_t out_size=in_size*4; + size_t in_size=utf7imapstring.size(); + size_t out_size=in_size*4; - char *buf = (char *)malloc(out_size+1); - if (buf == NULL) - throw runtime_error("out of memory for iconv buffer"); + char *buf = (char *)malloc(out_size+1); + if (buf == NULL) + throw runtime_error("out of memory for iconv buffer"); - const char *in = utf7imapstring.c_str(); - char *out = buf; - iconv (utf7imap2utf8, &in, &in_size, &out, &out_size); + const char *in = utf7imapstring.c_str(); + char *out = buf; + iconv(utf7imap2utf8, &in, &in_size, &out, &out_size); - buf[utf7imapstring.size()*4-out_size]=0; + buf[utf7imapstring.size()*4-out_size]=0; - result=buf; + result=buf; - free(buf); - iconv_close (utf7imap2utf8); + free(buf); + iconv_close(utf7imap2utf8); - return result; + return result; } std::string utf8_to_utf7imap(const std::string& utf8string) { - string result; + string result; - iconv_t utf82utf7imap = iconv_open ("UTF-7-IMAP", "UTF-8"); + iconv_t utf82utf7imap = iconv_open("UTF-7-IMAP", "UTF-8"); - if (utf82utf7imap == (iconv_t)-1) - throw runtime_error("iconv can't convert from UTF-7-IMAP to UTF-8"); + if (utf82utf7imap == (iconv_t)-1) + throw runtime_error("iconv can't convert from UTF-7-IMAP to UTF-8"); - // UTF-7 is base64 encoded, a buffer 10x as large - // as the utf-8 buffer should be enough. If not the string will be truncated. - size_t in_size=utf8string.size(); - size_t out_size=in_size*10; + // UTF-7 is base64 encoded, a buffer 10x as large + // as the utf-8 buffer should be enough. If not the string will be truncated. + size_t in_size=utf8string.size(); + size_t out_size=in_size*10; - char *buf = (char *)malloc(out_size+1); - if (buf == NULL) - throw runtime_error("out of memory for iconv buffer"); + char *buf = (char *)malloc(out_size+1); + if (buf == NULL) + throw runtime_error("out of memory for iconv buffer"); - const char *in = utf8string.c_str(); - char *out = buf; - iconv (utf82utf7imap, &in, &in_size, &out, &out_size); + const char *in = utf8string.c_str(); + char *out = buf; + iconv(utf82utf7imap, &in, &in_size, &out, &out_size); - buf[utf8string.size()*10-out_size]=0; + buf[utf8string.size()*10-out_size]= 0; - result=buf; + result=buf; - free(buf); - iconv_close (utf82utf7imap); + free(buf); + iconv_close(utf82utf7imap); - return result; + return result; } // Tokenize string by (html) tags void tokenize_by_tag(vector > &tokenized, const std::string &input) { - string::size_type pos, len = input.size(); - bool inside_tag = false; - string current; + string::size_type pos, len = input.size(); + bool inside_tag = false; + string current; + + for (pos = 0; pos < len; pos++) + { + if (input[pos] == '<') + { + inside_tag = true; + + if (!current.empty() ) + { + tokenized.push_back( make_pair(current, false) ); + current = ""; + } + + current += input[pos]; + } + else if (input[pos] == '>' && inside_tag) + { + current += input[pos]; + inside_tag = false; + if (!current.empty() ) + { + tokenized.push_back( make_pair(current, true) ); + current = ""; + } + } + else + current += input[pos]; + } + + // String left over in buffer? + if (!current.empty() ) + tokenized.push_back( make_pair(current, false) ); +} // eo tokenize_by_tag - for (pos = 0; pos < len; pos++) { - if (input[pos] == '<') { - inside_tag = true; - - if (!current.empty()) { - tokenized.push_back(make_pair(current, false)); - current = ""; - } - - current += input[pos]; - } else if (input[pos] == '>' && inside_tag) { - current += input[pos]; - inside_tag = false; - if (!current.empty()) { - tokenized.push_back(make_pair(current, true)); - current = ""; - } - } else - current += input[pos]; - } - - // String left over in buffer? - if (!current.empty()) - tokenized.push_back(make_pair(current, false)); -} std::string strip_html_tags(const std::string &input) { - // Pair first: string, second: isTag - vector > tokenized; - tokenize_by_tag(tokenized, input); + // Pair first: string, second: isTag + vector > tokenized; + tokenize_by_tag (tokenized, input); - string output; - vector >::const_iterator token, tokens_end = tokenized.end(); - for (token = tokenized.begin(); token != tokens_end; token++) - if (!token->second) - output += token->first; + string output; + vector >::const_iterator token, tokens_end = tokenized.end(); + for (token = tokenized.begin(); token != tokens_end; token++) + if (!token->second) + output += token->first; + + return output; +} // eo strip_html_tags - return output; -} // Smart-encode HTML en string smart_html_entities(const std::string &input) { - // Pair first: string, second: isTag - vector > tokenized; - tokenize_by_tag(tokenized, input); - - string output; - vector >::const_iterator token, tokens_end = tokenized.end(); - for (token = tokenized.begin(); token != tokens_end; token++) { - // keep HTML tags as they are - if (token->second) - output += token->first; - else - output += html_entities(token->first); - } - - return output; + // Pair first: string, second: isTag + vector > tokenized; + tokenize_by_tag (tokenized, input); + + string output; + vector >::const_iterator token, tokens_end = tokenized.end(); + for (token = tokenized.begin(); token != tokens_end; token++) + { + // keep HTML tags as they are + if (token->second) + output += token->first; + else + output += html_entities(token->first); + } + + return output; } + string::size_type find_8bit(const std::string &str) { - string::size_type l=str.size(); - for (string::size_type p=0; p < l; p++) - if (static_cast(str[p]) > 127) - return p; + string::size_type l=str.size(); + for (string::size_type p=0; p < l; p++) + if (static_cast(str[p]) > 127) + return p; - return string::npos; + return string::npos; } // encoded UTF-8 chars into HTML entities string html_entities(std::string str) { - // Normal chars - replace_all (str, "&", "&"); - replace_all (str, "\"", """); - replace_all (str, "<", "<"); - replace_all (str, ">", ">"); - - // Umlauts - replace_all (str, "\xC3\xA4", "ä"); - replace_all (str, "\xC3\xB6", "ö"); - replace_all (str, "\xC3\xBC", "ü"); - replace_all (str, "\xC3\x84", "Ä"); - replace_all (str, "\xC3\x96", "Ö"); - replace_all (str, "\xC3\x9C", "Ü"); - - // Misc - replace_all (str, "\xC3\x9F", "ß"); - - // conversion of remaining non-ASCII chars needed? - // just do if needed because of performance - if (find_8bit(str) != string::npos) - { - // convert to fixed-size encoding UTF-32 - wchar_t* wbuf=utf8_to_wbuf(str); - ostringstream target; - - // replace all non-ASCII chars with HTML representation - for (int p=0; wbuf[p] != 0; p++) - { - unsigned int c=wbuf[p]; - - if (c <= 127) - target << static_cast(c); - else - target << "&#" << c << ';'; - } - - free(wbuf); - - str=target.str(); - } - - return str; -} + // Normal chars + replace_all (str, "&", "&"); + replace_all (str, "\"", """); + replace_all (str, "<", "<"); + replace_all (str, ">", ">"); + + // Umlauts + replace_all (str, "\xC3\xA4", "ä"); + replace_all (str, "\xC3\xB6", "ö"); + replace_all (str, "\xC3\xBC", "ü"); + replace_all (str, "\xC3\x84", "Ä"); + replace_all (str, "\xC3\x96", "Ö"); + replace_all (str, "\xC3\x9C", "Ü"); + + // Misc + replace_all (str, "\xC3\x9F", "ß"); + + // conversion of remaining non-ASCII chars needed? + // just do if needed because of performance + if (find_8bit(str) != string::npos) + { + // convert to fixed-size encoding UTF-32 + wchar_t* wbuf=utf8_to_wbuf(str); + ostringstream target; + + // replace all non-ASCII chars with HTML representation + for (int p=0; wbuf[p] != 0; p++) + { + unsigned int c=wbuf[p]; + + if (c <= 127) + target << static_cast(c); + else + target << "&#" << c << ';'; + } + + free(wbuf); + + str=target.str(); + } + + return str; +} // eo html_entities(std::string) + bool replace_all(string &base, const char *ist, const char *soll) { - string i=ist; - string s=soll; - return replace_all(base,&i,&s); + string i=ist; + string s=soll; + return replace_all(base,&i,&s); } bool replace_all(string &base, const string &ist, const char *soll) { - string s=soll; - return replace_all(base,&ist,&s); + string s=soll; + return replace_all(base,&ist,&s); } bool replace_all(string &base, const string *ist, const string *soll) { - return replace_all(base,*ist,*soll); + return replace_all(base,*ist,*soll); } bool replace_all(string &base, const char *ist, const string *soll) { - string i=ist; - return replace_all(base,&i,soll); + string i=ist; + return replace_all(base,&i,soll); } bool replace_all(string &base, const string &ist, const string &soll) { - bool found_ist = false; - string::size_type a=0; + bool found_ist = false; + string::size_type a=0; + + if (ist.empty() ) + throw runtime_error ("replace_all called with empty search string"); - if (ist.empty()) - throw runtime_error("replace_all called with empty search string"); + while ( (a=base.find(ist,a) ) != string::npos) + { + base.replace(a,ist.size(),soll); + a=a+soll.size(); + found_ist = true; + } - while((a=base.find(ist,a))!=string::npos) - { - base.replace(a,ist.size(),soll); - a=a+soll.size(); - found_ist = true; - } - - return found_ist; + return found_ist; } string to_lower(const string &src) { - string dst = src; + string dst = src; - string::size_type pos, end = dst.size(); - for (pos = 0; pos < end; pos++) - dst[pos] = tolower(dst[pos]); + string::size_type pos, end = dst.size(); + for (pos = 0; pos < end; pos++) + dst[pos] = tolower(dst[pos]); - return dst; + return dst; } string to_upper(const string &src) { - string dst = src; + string dst = src; - string::size_type pos, end = dst.size(); - for (pos = 0; pos < end; pos++) - dst[pos] = toupper(dst[pos]); + string::size_type pos, end = dst.size(); + for (pos = 0; pos < end; pos++) + dst[pos] = toupper(dst[pos]); - return dst; + return dst; } -string nice_unit_format (int input) { - float size = input; - int sizecount = 0; - - while (size > 1000) { - size = size / 1000; - sizecount++; - } - - float tmp; // round - tmp = size*10; - tmp += 0.5; - tmp = int (tmp); - tmp = float(tmp)/float(10); - size = tmp; - - ostringstream out; - - out.setf (ios::fixed); - out.precision(2); - switch (sizecount) { - case 1: - out << size << i18n(" KBytes"); - break; - case 2: - out << size << i18n(" MBytes"); - break; - case 3: - out << size << i18n(" Gbytes"); - break; - default: - out << size << i18n(" Bytes"); - break; - } - - return out.str(); -} +string nice_unit_format(int input) +{ + float size = input; + int sizecount = 0; + + while (size > 1000) + { + size = size / 1000; + sizecount++; + } + + float tmp; // round + tmp = size*10; + tmp += 0.5; + tmp = int (tmp); + tmp = float (tmp) /float (10); + size = tmp; + + ostringstream out; + + out.setf (ios::fixed); + out.precision (2); + switch (sizecount) + { + case 0: + out << size << i18n (" Bytes"); + break; + case 1: + out << size << i18n (" KBytes"); + break; + case 2: + out << size << i18n (" MBytes"); + break; + case 3: + out << size << i18n (" GBytes"); + break; + case 4: + out << size << i18n (" TBytes"); + break; + case 5: + out << size << i18n (" PBytes"); + break; + case 6: + out << size << i18n (" EBytes"); + break; + default: + out << size << "*10^" << (sizecount*3)<< i18n (" Bytes"); + break; + } + + return out.str(); +} // eo nice_unit_format(int input) + string escape(const string &s) { - string out(s); - string::size_type p; - - p=0; - while ((p=out.find_first_of("\"\\",p))!=out.npos) - { - out.insert(p,"\\"); - p+=2; - } - - p=0; - while ((p=out.find_first_of("\r",p))!=out.npos) - { - out.replace(p,1,"\\r"); - p+=2; - } - - p=0; - while ((p=out.find_first_of("\n",p))!=out.npos) - { - out.replace(p,1,"\\n"); - p+=2; - } - - out='"'+out+'"'; - - return out; -} + string out(s); + string::size_type p; -string descape(const string &s, int startpos, int &endpos) -{ - string out; + p=0; + while ( (p=out.find_first_of("\"\\",p) ) !=out.npos) + { + out.insert (p,"\\"); + p+=2; + } - if (s.at(startpos) != '"') - throw out_of_range("value not type escaped string"); + p=0; + while ( (p=out.find_first_of("\r",p) ) !=out.npos) + { + out.replace (p,1,"\\r"); + p+=2; + } - out=s.substr(startpos+1); - string::size_type p=0; + p=0; + while ( (p=out.find_first_of("\n",p) ) !=out.npos) + { + out.replace (p,1,"\\n"); + p+=2; + } - // search for the end of the string - while((p=out.find("\"",p))!=out.npos) - { - int e=p-1; - bool escaped=false; + out='"'+out+'"'; - // the " might be escaped with a backslash - while(e>=0 && out.at(e)=='\\') - { - if (escaped == false) - escaped=true; - else - escaped=false; + return out; +} // eo scape(const std::string&) - e--; - } - if (escaped==false) - break; - else - p++; - } - - // we now have the end of the string - out=out.substr(0,p); - - // tell calling prog about the endposition - endpos=startpos+p+1; - - // descape all \ stuff inside the string now - p=0; - while((p=out.find_first_of("\\",p))!=out.npos) - { - switch(out.at(p+1)) - { - case 'r': +string descape(const string &s, int startpos, int &endpos) +{ + string out; + + if (s.at(startpos) != '"') + throw out_of_range("value not type escaped string"); + + out=s.substr(startpos+1); + string::size_type p=0; + + // search for the end of the string + while ( (p=out.find("\"",p) ) !=out.npos) + { + int e=p-1; + bool escaped=false; + + // the " might be escaped with a backslash + while (e>=0 && out.at (e) =='\\') + { + if (escaped == false) + escaped=true; + else + escaped=false; + + e--; + } + + if (escaped==false) + break; + else + p++; + } + + // we now have the end of the string + out=out.substr(0,p); + + // tell calling prog about the endposition + endpos=startpos+p+1; + + // descape all \ stuff inside the string now + p=0; + while ( (p=out.find_first_of("\\",p) ) !=out.npos) + { + switch (out.at(p+1) ) + { + case 'r': out.replace(p,2,"\r"); break; - case 'n': + case 'n': out.replace(p,2,"\n"); break; - default: + default: out.erase(p,1); - } - p++; - } + } + p++; + } + + return out; +} // eo descape(const std::string&,int,int&) - return out; -} string escape_shellarg(const string &input) { - string output = "'"; - string::const_iterator it, it_end = input.end(); - for (it = input.begin(); it != it_end; it++) { - if ((*it) == '\'') - output += "'\\'"; - - output += *it; - } - - output += "'"; - return output; + string output = "'"; + string::const_iterator it, it_end = input.end(); + for (it = input.begin(); it != it_end; it++) + { + if ( (*it) == '\'') + output += "'\\'"; + + output += *it; + } + + output += "'"; + return output; } diff --git a/src/stringfunc.hxx b/src/stringfunc.hxx index 2802d36..dffa81d 100644 --- a/src/stringfunc.hxx +++ b/src/stringfunc.hxx @@ -10,7 +10,7 @@ * * * (c) Copyright 2007-2008 by Intra2net AG - * + * * info@intra2net.com */ @@ -22,14 +22,15 @@ #include #include -namespace i2n { +namespace I2n +{ /* ** some useful constants: */ -extern const std::string whitespaces; -extern const std::string lineends; +extern const std::string Whitespaces; +extern const std::string LineEndings; /* @@ -37,40 +38,40 @@ extern const std::string lineends; */ -bool hasPrefix(const std::string& str, const std::string& prefix); +bool has_prefix(const std::string& str, const std::string& prefix); -bool hasSuffix(const std::string& str, const std::string& suffix); +bool has_suffix(const std::string& str, const std::string& suffix); /* -** tool functions (modifying): +** tool functions(modifying): */ -std::string trimMod(std::string& str, const std::string& charlist = whitespaces); +std::string trim_mod(std::string& str, const std::string& charlist = Whitespaces); -std::string chompMod(std::string& str, const std::string& what= lineends ); +std::string chomp_mod(std::string& str, const std::string& what= LineEndings ); -std::string lowerMod(std::string& str); +std::string to_lower_mod(std::string& str); -std::string upperMod(std::string& str); +std::string to_upper_mod(std::string& str); /* ** tool functions (not modifying): */ -std::string trim(const std::string& str, const std::string& charlist = whitespaces); +std::string trim(const std::string& str, const std::string& charlist = Whitespaces); -std::string chomp(const std::string& str, const std::string& what= lineends ); +std::string chomp(const std::string& str, const std::string& what= LineEndings ); -std::string lower(const std::string& str); +std::string to_lower(const std::string& str); -std::string upper(const std::string& str); +std::string to_upper(const std::string& str); -std::string removeSuffix(const std::string& str, const std::string& suffix); +std::string remove_suffix(const std::string& str, const std::string& suffix); -std::string removePrefix(const std::string& str, const std::string& prefix); +std::string remove_prefix(const std::string& str, const std::string& prefix); @@ -79,32 +80,32 @@ std::string removePrefix(const std::string& str, const std::string& prefix); */ -bool pairSplit( - const std::string& str, - std::string& key, - std::string& value, - char delimiter = '='); +bool pair_split( + const std::string& str, + std::string& key, + std::string& value, + char delimiter = '='); -void splitString( - const std::string& str, - std::list< std::string >& result, - const std::string& delimiter= "\n", - bool omit_empty= false, - const std::string& trim_list= std::string() +void split_string( + const std::string& str, + std::list< std::string >& result, + const std::string& delimiter= "\n", + bool omit_empty= false, + const std::string& trim_list= std::string() ); -std::list< std::string > splitString( - const std::string& str, - const std::string& delimiter = "\n", - bool omit_empty= false, - const std::string& trim_list= std::string() +std::list< std::string > split_string( + const std::string& str, + const std::string& delimiter = "\n", + bool omit_empty= false, + const std::string& trim_list= std::string() ); -std::string joinString( - const std::list< std::string >& parts, - const std::string& delimiter = "\n" +std::string join_string( + const std::list< std::string >& parts, + const std::string& delimiter = "\n" ); @@ -113,9 +114,9 @@ std::string joinString( */ -std::string binaryToHex(const std::string&str, bool upper_case_digits= false); +std::string convert_binary_to_hex(const std::string&str, bool upper_case_digits= false); -std::string hexToBinary(const std::string& str) throw(std::runtime_error); +std::string convert_hex_to_binary(const std::string& str) throw(std::runtime_error); @@ -131,15 +132,15 @@ std::string hexToBinary(const std::string& str) throw(std::runtime_error); * @return the value of type T. */ template< - class T +class T > -T stringTo(const std::string& s) +T string_to(const std::string& s) { - std::istringstream istr(s); - T result; - istr >> result; - return result; -} // eo stringTo(const std::string&) + std::istringstream istr(s); + T result; + istr >> result; + return result; +} // eo string_to(const std::string&) /** @@ -150,14 +151,14 @@ T stringTo(const std::string& s) * @return @a true iff the internal string stream was EOF after the conversion. */ template< - class T +class T > -bool stringTo(const std::string& s, T& result) +bool string_to(const std::string& s, T& result) { - std::istringstream istr(s); - istr >> result; - return istr.eof(); -} // eo stringTo(const std::string&) + std::istringstream istr(s); + istr >> result; + return istr.eof(); +} // eo string_to(const std::string&) /** @@ -167,21 +168,24 @@ bool stringTo(const std::string& s, T& result) * @return the resulting string. */ template< - class T +class T > -std::string toString(const T& v) +std::string to_string(const T& v) { - std::ostringstream ostr; - ostr << v; - return ostr.str(); -} // eo toString(const T&) + std::ostringstream ostr; + ostr << v; + return ostr.str(); +} // eo to_string(const T&) + + +} // eo namespace I2n + -} // eo namespace i2n -std::string to_lower (const std::string &src); -std::string to_upper (const std::string &src); +std::string to_lower(const std::string &src); +std::string to_upper(const std::string &src); -std::string nice_unit_format (int input); +std::string nice_unit_format(int input); bool replace_all(std::string &base, const std::string *ist, const std::string *soll); bool replace_all(std::string &base, const char *ist, const char *soll); @@ -203,8 +207,8 @@ std::string escape(const std::string &s); std::string descape(const std::string &s, int startpos, int &endpos); inline std::string descape(const std::string &s) { - int endpos; - return descape(s,0,endpos); + int endpos; + return descape(s,0,endpos); } std::string escape_shellarg(const std::string &input); -- 1.7.1