1 karl 1.18 //%2003////////////////////////////////////////////////////////////////////////
|
2 mike 1.13 //
|
3 karl 1.18 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
|
7 mike 1.13 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 kumpf 1.15 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12 mike 1.13 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
|
15 kumpf 1.15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
16 mike 1.13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
18 kumpf 1.15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
21 mike 1.13 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Mike Brasher (mbrasher@bmc.com)
27 //
28 // Modified By:
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <iostream>
33 #include <cstdio>
34 #include "Formatter.h"
35
36 PEGASUS_NAMESPACE_BEGIN
37
38 String Formatter::Arg::toString() const
39 {
40 switch (_type)
41 {
42 mike 1.13 case INTEGER:
43 {
44 char buffer[32];
45 sprintf(buffer, "%d", _integer);
46 return buffer;
47 }
48
49 case UINTEGER:
50 {
51 char buffer[32];
52 sprintf(buffer, "%u", _integer);
53 return buffer;
54 }
55
56 case BOOLEAN:
57 {
58 //char buffer[32];
59 //buffer = (_boolean ? "true": "false");
60 //return buffer;
61 return (_boolean ? "true": "false");
62 }
63 mike 1.13
64 case REAL:
65 {
66 char buffer[32];
67 sprintf(buffer, "%f", _real);
68 return buffer;
69 }
70
71 case LINTEGER:
72 {
73 char buffer[32];
74 // ATTN-B: truncation here!
75 sprintf(buffer, "%ld", long(_lInteger));
76 return buffer;
77 }
78
79 case ULINTEGER:
80 {
81 char buffer[32];
82 // ATTN-B: truncation here:
83 sprintf(buffer, "%lu", long(_lUInteger));
84 mike 1.13 return buffer;
85 }
86
87 case STRING:
88 return _string;
89
|
90 mike 1.14 case VOIDT:
|
91 mike 1.13 default:
92 return String();
93 }
94 }
95
96 String Formatter::format(
97 const String& formatString,
98 const Arg& arg0,
99 const Arg& arg1,
100 const Arg& arg2,
101 const Arg& arg3,
102 const Arg& arg4,
103 const Arg& arg5,
104 const Arg& arg6,
105 const Arg& arg7,
106 const Arg& arg8,
107 const Arg& arg9)
108 {
109 String result;
110
|
111 kumpf 1.16 for (Uint32 i = 0; i < formatString.size(); i++)
|
112 mike 1.13 {
|
113 kumpf 1.16 if (formatString[i] == '$')
|
114 mike 1.13 {
|
115 kumpf 1.16 Char16 c = formatString[++i];
|
116 mike 1.13
117 switch (c)
118 {
|
119 kumpf 1.17 case '0': result.append(arg0.toString()); break;
120 case '1': result.append(arg1.toString()); break;
121 case '2': result.append(arg2.toString()); break;
122 case '3': result.append(arg3.toString()); break;
123 case '4': result.append(arg4.toString()); break;
124 case '5': result.append(arg5.toString()); break;
125 case '6': result.append(arg6.toString()); break;
126 case '7': result.append(arg7.toString()); break;
127 case '8': result.append(arg8.toString()); break;
128 case '9': result.append(arg9.toString()); break;
|
129 mike 1.13 default: break;
130 }
131 }
|
132 kumpf 1.16 else if (formatString[i] == '\\')
|
133 mike 1.13 {
|
134 kumpf 1.17 result.append(formatString[++i]);
|
135 mike 1.13 }
136 else
|
137 kumpf 1.17 result.append(formatString[i]);
|
138 mike 1.13 }
139
140 return result;
141 }
142
143 PEGASUS_NAMESPACE_END
|