1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Location Centre Server object. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <utf.h> |
|
21 |
|
22 // USER INCLUDES |
|
23 #include "lcregxmlparserutils.h" |
|
24 #include "lcregxmltagtype.h" |
|
25 |
|
26 // CONSTANTS |
|
27 const TInt KBufLength = 30; |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // LcRegXmlParserUtils::Utf8ToUnicodeL |
|
33 // |
|
34 // (other items were commented in a header). |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 void LcRegXmlParserUtils::Utf8ToUnicodeL( |
|
38 const TDesC8& aUtf8, |
|
39 TDes16& aUnicode) |
|
40 { |
|
41 // Create a small output buffer |
|
42 TBuf16<KBufLength> output; |
|
43 // Create a buffer for the unconverted text |
|
44 TPtrC8 remUtf8(aUtf8); |
|
45 |
|
46 TBool convertingReady = EFalse; |
|
47 while (!convertingReady) // conversion loop |
|
48 { |
|
49 // Start conversion. When the output buffer is full, return the |
|
50 // number of characters that were not converted |
|
51 const TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8( |
|
52 output, remUtf8); |
|
53 |
|
54 // check to see that the descriptor isn't corrupt - leave if it is |
|
55 if (err == CnvUtfConverter::EErrorIllFormedInput) |
|
56 { |
|
57 User::Leave(KErrCorrupt); |
|
58 } |
|
59 else if (err < 0) // future-proof against "TError" expanding |
|
60 { |
|
61 User::Leave(KErrGeneral); |
|
62 } |
|
63 |
|
64 // Do something here to store the contents of the output buffer. |
|
65 if (aUnicode.Length() + output.Length() > aUnicode.MaxLength()) |
|
66 { |
|
67 User::Leave(KErrNoMemory); |
|
68 } |
|
69 aUnicode.Append(output); |
|
70 |
|
71 // Finish conversion if there are no unconverted characters in the |
|
72 // remainder buffer |
|
73 if (err == 0) |
|
74 { |
|
75 convertingReady = ETrue; |
|
76 } |
|
77 else |
|
78 { |
|
79 // Remove the converted source text from the remainder buffer. |
|
80 // The remainder buffer is then fed back into loop |
|
81 remUtf8.Set(remUtf8.Right(err)); |
|
82 } |
|
83 } |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // LcRegXmlParserUtils::OnlyWhiteSpaces |
|
88 // |
|
89 // (other items were commented in a header). |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TBool LcRegXmlParserUtils::OnlyWhiteSpaces( |
|
93 const TDesC8& aStr) |
|
94 { |
|
95 for (TInt i=0; i<aStr.Length(); i++) |
|
96 { |
|
97 TChar ch = TChar(aStr[i]); |
|
98 if (!ch.IsSpace()) |
|
99 { |
|
100 return EFalse; |
|
101 } |
|
102 } |
|
103 |
|
104 return ETrue; |
|
105 } |
|
106 // End of File |
|