@@ -53,27 +53,21 @@ internal enum HebrewNumberParsingState
53
53
// Hebrew text and parsing Hebrew number text.
54
54
//
55
55
// Limitations:
56
- // Parse can only handles value 1 ~ 999.
57
- // ToString () can only handles 1 ~ 999. If value is greater than 5000,
56
+ // Parse can only handle value 1 ~ 999.
57
+ // Append () can only handle 1 ~ 999. If value is greater than 5000,
58
58
// 5000 will be subtracted from the value.
59
59
//
60
60
////////////////////////////////////////////////////////////////////////////
61
61
62
- internal class HebrewNumber
62
+ internal static class HebrewNumber
63
63
{
64
- // This class contains only static methods. Add a private ctor so that
65
- // compiler won't generate a default one for us.
66
- private HebrewNumber ( )
67
- {
68
- }
69
-
70
64
////////////////////////////////////////////////////////////////////////////
71
65
//
72
- // ToString
66
+ // Append
73
67
//
74
68
// Converts the given number to Hebrew letters according to the numeric
75
- // value of each Hebrew letter. Basically, this converts the lunar year
76
- // and the lunar month to letters.
69
+ // value of each Hebrew letter, appending to the supplied StringBuilder.
70
+ // Basically, this converts the lunar year and the lunar month to letters.
77
71
//
78
72
// The character of a year is described by three letters of the Hebrew
79
73
// alphabet, the first and third giving, respectively, the days of the
@@ -87,13 +81,14 @@ private HebrewNumber()
87
81
//
88
82
////////////////////////////////////////////////////////////////////////////
89
83
90
- internal static string ToString ( int Number )
84
+ internal static void Append ( StringBuilder outputBuffer , int Number )
91
85
{
86
+ Debug . Assert ( outputBuffer != null ) ;
87
+ int outputBufferStartingLength = outputBuffer . Length ;
88
+
92
89
char cTens = '\x0 ';
93
90
char cUnits ; // tens and units chars
94
91
int Hundreds , Tens ; // hundreds and tens values
95
- StringBuilder szHebrew = new StringBuilder ( ) ;
96
-
97
92
98
93
//
99
94
// Adjust the number if greater than 5000.
@@ -120,13 +115,13 @@ internal static string ToString(int Number)
120
115
// If the number is greater than 400, use the multiples of 400.
121
116
for ( int i = 0 ; i < ( Hundreds / 4 ) ; i ++ )
122
117
{
123
- szHebrew . Append ( '\x05ea ' ) ;
118
+ outputBuffer . Append ( '\x05ea ' ) ;
124
119
}
125
120
126
121
int remains = Hundreds % 4 ;
127
122
if ( remains > 0 )
128
123
{
129
- szHebrew . Append ( ( char ) ( ( int ) '\x05e6 ' + remains ) ) ;
124
+ outputBuffer . Append ( ( char ) ( ( int ) '\x05e6 ' + remains ) ) ;
130
125
}
131
126
}
132
127
@@ -195,27 +190,22 @@ internal static string ToString(int Number)
195
190
196
191
if ( cTens != '\x0 ')
197
192
{
198
- szHebrew . Append ( cTens ) ;
193
+ outputBuffer . Append ( cTens ) ;
199
194
}
200
195
201
196
if ( cUnits != '\x0 ')
202
197
{
203
- szHebrew . Append ( cUnits ) ;
198
+ outputBuffer . Append ( cUnits ) ;
204
199
}
205
200
206
- if ( szHebrew . Length > 1 )
201
+ if ( outputBuffer . Length - outputBufferStartingLength > 1 )
207
202
{
208
- szHebrew . Insert ( szHebrew . Length - 1 , '"' ) ;
203
+ outputBuffer . Insert ( outputBuffer . Length - 1 , '"' ) ;
209
204
}
210
205
else
211
206
{
212
- szHebrew . Append ( '\' ' ) ;
207
+ outputBuffer . Append ( '\' ' ) ;
213
208
}
214
-
215
- //
216
- // Return success.
217
- //
218
- return ( szHebrew . ToString ( ) ) ;
219
209
}
220
210
221
211
////////////////////////////////////////////////////////////////////////////
0 commit comments