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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/////////////////////////////////////////////////////////////////////////////
// Name: pokemod/String.cpp
// Purpose: A custom string class derived from the C++ standard string
// to accomodate simple format functionality
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Mon Feb 19 22:03:45 2007
// Copyright: ©2007 Nerdy Productions
// Licence:
// 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.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/////////////////////////////////////////////////////////////////////////////
#include "String.h"
PokeGen::PokeMod::String::String(const std::string &str)
{
assign(str);
}
PokeGen::PokeMod::String::String(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
printf(fmt, args);
va_end(args);
}
void PokeGen::PokeMod::String::printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
printf(fmt, args);
va_end(args);
}
void PokeGen::PokeMod::String::printf(const char *fmt, va_list &args)
{
Format unit;
std::stringstream ss;
const char *p = fmt;
while (*p)
{
if (*p == '%')
{
if (*++p)
{
switch (*p)
{
// C-strings
case 's':
unit.s = va_arg(args, const char *);
append(unit.s);
break;
// Integers
case 'i':
case 'd':
unit.i = va_arg(args, int);
ss.str("");
ss << unit.i;
append(ss.str());
break;
// Unsigned integers
case 'u':
unit.u = va_arg(args, unsigned);
ss.str("");
ss << unit.u;
append(ss.str());
break;
// Longs
case 'I':
case 'D':
unit.l = va_arg(args, long);
ss.str("");
ss << unit.l;
append(ss.str());
break;
// Unsigned longs
case 'U':
unit.ul = va_arg(args, unsigned long);
ss.str("");
ss << unit.ul;
append(ss.str());
break;
// Characters
case 'c':
unit.c = (char)va_arg(args, int);
append(1, unit.c);
break;
// Unsigned characters
case 'x':
unit.uc = (unsigned char)va_arg(args, int);
append(1, unit.uc);
break;
// Floats
case 'f':
unit.f = va_arg(args, double);
ss.str("");
ss << unit.f;
append(ss.str());
break;
// Percent character
case '%':
append(1, '%');
break;
// Unknown sequence
default:
append(1, '%');
append(1, *p);
}
}
else
{
append(1, '%');
break;
}
}
else
append(1, *p);
++p;
}
}
PokeGen::PokeMod::String::operator const char *() const
{
return c_str();
}
|