1 #ifndef __msn_util_h__ 2 #define __msn_util_h__ 3 4 /* 5 * util.h 6 * libmsn 7 * 8 * Created by Mark Rowe on Mon Mar 22 2004. 9 * Copyright (c) 2004 Mark Rowe. All rights reserved. 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 #include <string> 27 #include <map> 28 #include <vector> 29 #include <stdexcept> 30 31 namespace MSN 32 { 33 /** URL-encode a string 34 * 35 * @param s The string to encode. 36 * @return A string with all non-alphanumeric characters replaced by their 37 * URL-encoded equivalent. 38 */ 39 std::string encodeURL(const std::string & s); 40 41 /** URL-decode a string 42 * 43 * @param s The URL-encoded string to decode. 44 * @return A string with all URL-encoded sequences replaced by their 45 * @c ASCII equivalent. 46 */ 47 std::string decodeURL(const std::string & s); 48 49 /** Split a string containing a hostname and port number into its respective parts. 50 * 51 * @param address A string in the form "hostname:port". 52 * @param default_port A port number to return in the event that ":port" is omitted from @a address. 53 * @return A pair containing the hostname and port number. 54 */ 55 std::pair<std::string, int> splitServerAddress(const std::string & address, int default_port=1863); 56 57 /** Compare two strings in a case insensitive fashion 58 */ 59 int nocase_cmp(const std::string & s1, const std::string & s2); 60 61 /** Split @a string at each occurence of @a separator. 62 */ 63 std::vector<std::string> splitString(const std::string & string, const std::string & separator, bool suppressBlanks=true); 64 65 /** Convert a string, @a s, that contains decimal digits into an unsigned int. 66 */ 67 unsigned int decimalFromString(const std::string & s) throw (std::logic_error); 68 } 69 #endif 70