Small OpenGL based c++ rendering library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

extstring.cpp 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* libsegl - Sebas Extended GL Library
  2. * Collection of Opengl/3D-Math helpers
  3. *
  4. * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
  5. * http://www.seba-geek.de
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. */
  22. #include "extstring.h"
  23. namespace segl {
  24. int explode(std::string str, std::string delim, std::vector<std::string> *erg, bool clean) {
  25. erg->clear();
  26. int treffer=0;
  27. std::string tmp;
  28. unsigned int pos;
  29. while((pos = str.find(delim))!=std::string::npos) {
  30. tmp = str.substr(0, pos);
  31. if(!clean || tmp!="") {
  32. // tmp nicht leer, hinzufügen
  33. erg->push_back(tmp);
  34. treffer++;
  35. }
  36. str = str.substr(pos+1); // alten kram entfernen
  37. }
  38. if(str.length()>0) {
  39. treffer++;
  40. erg->push_back(str);
  41. }
  42. return treffer;
  43. }
  44. std::string trim(std::string t) {
  45. while(t.length() && isspace(t[0])) {
  46. t = t.substr(1);
  47. }
  48. while(t.length() && ( isspace(t[t.length()-1]) )) {
  49. t = t.substr(0, t.length()-2);
  50. }
  51. return t;
  52. }
  53. std::string basename(std::string str) {
  54. return str.substr( str.rfind("/"));
  55. }
  56. std::string rbasename(std::string str) {
  57. return str.substr(0, str.rfind("/")+1);
  58. }
  59. } // namespace segl