-
Notifications
You must be signed in to change notification settings - Fork 0
/
SString.cc
executable file
·112 lines (88 loc) · 3.68 KB
/
SString.cc
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
/* =========FOR INTERNAL USE ONLY. NO DISTRIBUTION PLEASE ========== */
/*********************************************************************
Copyright 2000-2001, Princeton University. All rights reserved.
By using this software the USER indicates that he or she has read,
understood and will comply with the following:
--- Princeton University hereby grants USER nonexclusive permission
to use, copy and/or modify this software for internal, noncommercial,
research purposes only. Any distribution, including commercial sale
or license, of this software, copies of the software, its associated
documentation and/or modifications of either is strictly prohibited
without the prior consent of Princeton University. Title to copyright
to this software and its associated documentation shall at all times
remain with Princeton University. Appropriate copyright notice shall
be placed on all software copies, and a complete copy of this notice
shall be included in all copies of the associated documentation.
No right is granted to use in advertising, publicity or otherwise
any trademark, service mark, or the name of Princeton University.
--- This software and any associated documentation is provided "as is"
PRINCETON UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS
OR IMPLIED, INCLUDING THOSE OF MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE, OR THAT USE OF THE SOFTWARE, MODIFICATIONS, OR
ASSOCIATED DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS,
TRADEMARKS OR OTHER INTELLECTUAL PROPERTY RIGHTS OF A THIRD PARTY.
Princeton University shall not be liable under any circumstances for
any direct, indirect, special, incidental, or consequential damages
with respect to any claim by USER or any third party on account of
or arising from the use, or inability to use, this software or its
associated documentation, even if Princeton University has been advised
of the possibility of those damages.
*********************************************************************/
#include "SString.h"
#include "SStd.h"
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <iostream>
/*###########################################################################*/
namespace {
template <typename T>
T convert(const string & s) {
istrstream iss(s.c_str());
double dbl;
iss >> dbl;
// FIXME: Insert check when MAX and MIN templates are supported.
Sassert(! iss.bad());
return static_cast<T>(dbl);
}
/* template <>
bool convert<bool>(const string & s) {
insen_equal_to<string> eq;
if (eq(s, "true") || eq(s, "t") || eq(s, "1")) {
return true;
} else if (eq(s, "false") || eq(s, "f") || eq(s, "0")) {
return false;
}
sabort();
return false;
}
*/
}
Conv::Conv(const string & str) :
str_(str)
{}
/*===========================================================================*/
Conv::operator bool()
{ return convert<bool>(str_); }
Conv::operator signed char()
{ return convert<char>(str_); }
Conv::operator unsigned char()
{ return convert<unsigned char>(str_); }
Conv::operator short()
{ return convert<short>(str_); }
Conv::operator unsigned short()
{ return convert<unsigned short>(str_); }
Conv::operator int()
{ return convert<int>(str_); }
Conv::operator unsigned()
{ return convert<unsigned>(str_); }
Conv::operator long()
{ return convert<long>(str_); }
Conv::operator unsigned long()
{ return convert<unsigned long>(str_); }
Conv::operator float()
{ return convert<float>(str_); }
Conv::operator double()
{ return convert<double>(str_); }
/*===========================================================================*/