equal
deleted
inserted
replaced
|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // STDIO functions implemented over EPOC32 |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <_ansi.h> |
|
20 #include <stdio_r.h> |
|
21 |
|
22 #define UNUSED_VAR(a) a = a |
|
23 |
|
24 extern "C" { |
|
25 int e32cvt (char *buf, int buflen, double d, int width, int prec, int /*flags*/, int fchar) |
|
26 { |
|
27 TPtr8 res((TText8*)buf, buflen); |
|
28 TBuf8<0x50> fmt; |
|
29 TBool capitalE=EFalse; |
|
30 switch(fchar) |
|
31 { |
|
32 case 'f': |
|
33 fchar='f'; |
|
34 break; |
|
35 |
|
36 case 'E': |
|
37 capitalE=ETrue; // and fallthrough |
|
38 case 'e': |
|
39 fchar='e'; |
|
40 break; |
|
41 |
|
42 case 'G': |
|
43 capitalE=ETrue; // and fallthrough |
|
44 case 'g': |
|
45 fchar='g'; |
|
46 break; |
|
47 default: |
|
48 return 0; |
|
49 } |
|
50 // construct a format string for use with TDes::Format - we can't use the |
|
51 // VFPRINTF original because it doesn't quite match and it might involve '*' |
|
52 // to read field widths from VFPRINTF arguments. |
|
53 fmt.Zero(); |
|
54 fmt.Append('%'); |
|
55 // flags? |
|
56 if (width) |
|
57 fmt.AppendNum(width); |
|
58 if (prec>=0) |
|
59 { |
|
60 fmt.Append('.'); |
|
61 fmt.AppendNum(prec); |
|
62 } |
|
63 fmt.Append(fchar); |
|
64 TRAPD(r,res.Format(fmt,d)); |
|
65 UNUSED_VAR(r); |
|
66 if (capitalE) |
|
67 { |
|
68 TInt pos=res.Locate('e'); |
|
69 if (pos!=KErrNotFound) |
|
70 res[pos]='E'; |
|
71 } |
|
72 return res.Length(); |
|
73 } |
|
74 } |