File: String.h

package info (click to toggle)
realtimebattle 1.0.7-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,016 kB
  • ctags: 4,397
  • sloc: cpp: 19,292; ansic: 8,925; sh: 4,579; makefile: 1,174; java: 734; yacc: 288; perl: 141; sed: 16
file content (88 lines) | stat: -rw-r--r-- 2,737 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
RealTimeBattle, a robot programming game for Unix
Copyright (C) 1998-2000  Erik Ouchterlony and Ragnar Ouchterlony

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef __STRING__
#define __STRING__

#include <iostream>

using namespace std;

enum string_double_t { STRING_NORMAL_FORM, STRING_EXP_FORM, STRING_FIXED_FORM };

class String
{
public:
  String();
  String(const String& str);
  String(const char* str);
  String(const char c);
  String(const int);
  String(const long int);
  String(const double, const int digits = 10, const string_double_t form = STRING_NORMAL_FORM);
  ~String();

  String& operator=(const String&);
  String& operator=(const char);
  String& operator=(const char*);
  friend String operator+(const String&, const String&);
  friend int operator==(const String&, const String&);
  friend int operator!=(const String&, const String&);
  String& operator+=(const String&);

  char operator[](int) const;

  friend ostream& operator<<(ostream&, const String&);
  friend istream& operator>>(istream&, String&);  

  friend int str2int(const String&);
  friend long str2long(const String&);
  friend double str2dbl(const String&);
  friend long str2hex(const String&);
  friend String hex2str(const long);

  String& erase(const int pos, const int size = 1);
  String& insert(const String&, const int pos = 0);
  int find( const char c, const int start = 0, const bool reverse = false ) const;
  friend String get_segment(const String& str, const int start, const int end);
  friend String make_lower_case(const String& str);

  int get_length() const { return length; }
  bool is_empty() const { return length == 0; }
  const char* chars() const { return array; }

   //  Warning! This allows for changing the private member array.
  char* non_const_chars() const { return array; }

  // allocates an array of chars, remember to delete afterwards!
  char* copy_chars(); 

private:
  char* array;
  int length;
  int buf_size;

  //  String& copy(const String&);
  void allocate_array(const int size);
  void enlarge_array(const int size);

  class Range {};
};

#endif