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