src/utils/utility.cpp

00001 /* 
00002  * wsdlpull- A C++ parser  for WSDL  (Web services description language)
00003  * Copyright (C) 2003 Vivek Krishna
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public
00016  * License along with this library; if not, write to the Free
00017  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  *
00019  *
00020  */
00021 
00022 #include <utils/utils.h>
00023 
00024 //put all I/O and string manip  utiliy functions here
00025 int
00026 parseInt (string s, int radix)
00027 {
00028   int len = s.size ();
00029   int value = 0;
00030   if (s.empty ())
00031     return -1;
00032   for (int i = 0; i < len; i++) {
00033     if (radix == 10) {
00034       if (s[i] <= '9' && s[i] >= 0)
00035         value = (i == 0) ? (s[i] - '0') : radix * value + (s[i] - '0');
00036 
00037       else
00038         throw exception ();
00039     }
00040     else if (radix == 16) {
00041       //assumes that the encoding format has arranges the alphabets and numbers in increasing order
00042       if (s[i] <= '9' && s[i] >= 0)
00043         value = (i == 0) ? (s[i] - '0') : radix * value + (s[i] - '0');
00044 
00045       else if (s[i] <= 'F' && s[i] >= 'A')
00046         value =
00047           (i ==
00048            0) ? (s[i] - 'A') + 10 : radix * value + (s[i] - 'A') + 10;
00049 
00050       else if (s[i] <= 'f' && s[i] >= 'a')
00051         value =(i ==0) ? (s[i] - 'a') + 10 : radix * value + (s[i] - 'a') + 10;
00052     }
00053   }
00054   return value;
00055 }
00056 
00057 
00058 //Manipulators for intermediate format output
00059 ostream & dbsp (ostream & str)
00060 {
00061   return str << "  ";
00062 }
00063 
00064 
00065 ostream & blk (ostream & str)
00066 {
00067   return str << endl << "*************" << endl;
00068 }

Generated on Sun Aug 5 20:01:34 2007 for wsdlpull by  doxygen 1.4.6