ACT-CV - Machine Vision for Cognitive Modeling
GCString.h
Go to the documentation of this file.
1 // -*- mode: c++; indent-tabs-mode: nil; c-basic-offset: 4; coding: iso-8859-1; -*-
2 
3 /*
4 ACT-CV - Machine Vision for Cognitive Modeling
5 Copyright (c) 2008 Marc Halbruegge
6 
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11 
12 This program 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
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 
22 
27 #ifndef _GCSTRING_H
28 #define _GCSTRING_H
29 
30 #include <string>
31 #include <cctype>
32 
33 #include "garbagecoll.h"
34 
42 class GCString : public ReferenceCount {
43  std::string m_s;
44 public:
45  GCString(const char *s) : m_s(s) {}
46  GCString(const std::string &s) : m_s(s) {}
47  GCString(const char *s, int n) {
48  m_s.assign(s, s+n);
49  }
50  const char* GetString() const {
51  return m_s.c_str();
52  }
53  const size_t GetSize() const {
54  return m_s.length();
55  }
56 };
57 
59 class GCWString : public ReferenceCount {
60  std::wstring m_s;
61  GCWString() {}
62 public:
63  GCWString(const wchar_t *s) : m_s(s) {}
64  GCWString(const std::wstring &s) : m_s(s) {}
65  GCWString(const char *s) {
66  m_s.reserve(strlen(s));
67  const char *p = s;
68  while(*p) m_s.push_back(*p++);
69  }
70  GCWString(const wchar_t *s, unsigned int first, unsigned int lastPlusOne) {
71  m_s.assign(s+first, s+lastPlusOne);
72  }
73  GCWString(const std::string &s) {
74  m_s.reserve(s.size());
75  const char *p = s.c_str();
76  while(*p) m_s.push_back(*p++);
77  }
78  const wchar_t* GetString() const {
79  return m_s.c_str();
80  }
81  const size_t GetSize() const {
82  return m_s.length();
83  }
84  GCWString SubString(unsigned int first, unsigned int lastPlusOne) const {
85  return GCWString(m_s.substr(first, lastPlusOne-first));
86  }
87  void ToLower() {
88  for (size_t i=0;i<m_s.size();++i)
89  m_s[i] = std::tolower(m_s[i]);
90  }
91 };
92 
93 #endif
94 


ACT-CV - Machine Vision for Cognitive Modeling
© 2015 Marc Halbruegge (actcvlibrary@googlemail.com)