|
|
1.1 root 1: /*
2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
3:
4: Governed by the TrueCrypt License 2.4 the full text of which is contained
5: in the file License.txt included in TrueCrypt binary and source code
6: distribution packages.
7: */
8:
9: #include "System.h"
10: #include "StringFormatter.h"
11: #include "UserInterfaceException.h"
12:
13: namespace TrueCrypt
14: {
15: StringFormatter::StringFormatter (const wxString &format, StringFormatterArg arg0, StringFormatterArg arg1, StringFormatterArg arg2, StringFormatterArg arg3, StringFormatterArg arg4, StringFormatterArg arg5, StringFormatterArg arg6, StringFormatterArg arg7, StringFormatterArg arg8, StringFormatterArg arg9)
16: {
17: bool numberExpected = false;
18: bool endTagExpected = false;
19: foreach (wchar_t c, wstring (format))
20: {
21: if (numberExpected)
22: {
23: endTagExpected = true;
24: bool err = false;
25:
26: switch (c)
27: {
28: case L'{': FormattedString += L'{'; endTagExpected = false; break; // Escaped {
29:
30: case L'0': FormattedString += arg0; err = arg0.IsEmpty(); break;
31: case L'1': FormattedString += arg1; err = arg1.IsEmpty(); break;
32: case L'2': FormattedString += arg2; err = arg2.IsEmpty(); break;
33: case L'3': FormattedString += arg3; err = arg3.IsEmpty(); break;
34: case L'4': FormattedString += arg4; err = arg4.IsEmpty(); break;
35: case L'5': FormattedString += arg5; err = arg5.IsEmpty(); break;
36: case L'6': FormattedString += arg6; err = arg6.IsEmpty(); break;
37: case L'7': FormattedString += arg7; err = arg7.IsEmpty(); break;
38: case L'8': FormattedString += arg8; err = arg8.IsEmpty(); break;
39: case L'9': FormattedString += arg9; err = arg9.IsEmpty(); break;
40:
41: default: err = true; break;
42: }
43:
44: if (err)
45: throw StringFormatterException (SRC_POS, wstring (format));
46:
47: numberExpected = false;
48: }
49: else if (endTagExpected)
50: {
51: if (c != L'}')
52: throw StringFormatterException (SRC_POS, wstring (format));
53:
54: endTagExpected = false;
55: }
56: else if (c == L'{')
57: {
58: numberExpected = true;
59: }
60: else if (c == L'}')
61: {
62: FormattedString += c;
63: endTagExpected = true;
64: }
65: else
66: FormattedString += c;
67: }
68:
69: if (numberExpected
70: || endTagExpected
71: || !arg0.WasReferenced() && !arg0.IsEmpty()
72: || !arg1.WasReferenced() && !arg1.IsEmpty()
73: || !arg2.WasReferenced() && !arg2.IsEmpty()
74: || !arg3.WasReferenced() && !arg3.IsEmpty()
75: || !arg4.WasReferenced() && !arg4.IsEmpty()
76: || !arg5.WasReferenced() && !arg5.IsEmpty()
77: || !arg6.WasReferenced() && !arg6.IsEmpty()
78: || !arg7.WasReferenced() && !arg7.IsEmpty()
79: || !arg8.WasReferenced() && !arg8.IsEmpty()
80: || !arg9.WasReferenced() && !arg9.IsEmpty()
81: )
82: throw StringFormatterException (SRC_POS, wstring (format));
83: }
84:
85: StringFormatter::~StringFormatter ()
86: {
87: }
88: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.