jspace/jspace/strutil.cpp

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2006 Roland Philippsen <roland dot philippsen at gmx dot net>
00003  *
00004  * BSD license:
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holder nor the names of
00014  *    contributors to this software may be used to endorse or promote
00015  *    products derived from this software without specific prior written
00016  *    permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS''
00019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00020  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00021  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
00022  * HOLDER OR THE CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00024  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00025  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00027  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00038 #include "strutil.hpp"
00039 using namespace std;
00040 
00041 namespace sfl {
00042   
00043   template<>
00044   std::string to_string<bool>(const bool & flag) {
00045     if (flag)
00046       return "true";
00047     return "false";      
00048   }
00049   
00050   
00051   template<>
00052   bool string_to<bool>(const std::string & str, bool & foo) {
00053     if((str == "true") || (str == "TRUE") || (str == "True")
00054        || (str == "on") || (str == "ON") || (str == "On")){
00055       foo = true;
00056       return true;
00057     }
00058     else if((str == "false") || (str == "FALSE") || (str == "False")
00059       || (str == "off") || (str == "OFF") || (str == "Off")){
00060       foo = false;
00061       return true;
00062     }
00063     return false;
00064   }
00065   
00066   
00067   bool splitstring(string const & input, char separator,
00068        string & head, string & tail)
00069   {
00070     if (input.empty()) {
00071       head = "";
00072       tail = "";
00073       return false;
00074     }
00075     string::size_type col(input.find(separator, 0));
00076     head = input.substr(0, col);
00077     if (string::npos != col)
00078       tail = input.substr(col + 1);
00079     else
00080       tail = "";
00081     return true;
00082   }
00083   
00084 }

Generated on Fri Aug 26 01:31:16 2011 for Stanford Whole-Body Control Framework by  doxygen 1.5.4