]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/antlr2/src/String.cpp
Security-59306.101.1.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / antlr2 / src / String.cpp
1 /* ANTLR Translator Generator
2 * Project led by Terence Parr at http://www.jGuru.com
3 * Software rights: http://www.antlr.org/license.html
4 *
5 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/src/String.cpp#2 $
6 */
7
8 #include "antlr/String.hpp"
9
10 #include <cctype>
11
12 #ifdef HAS_NOT_CSTDIO_H
13 #include <stdio.h>
14 #else
15 #include <cstdio>
16 #endif
17
18 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
19 namespace antlr {
20 #endif
21
22 // wh: hack for Borland C++ 5.6
23 #if __BORLANDC__
24 using std::sprintf;
25 #endif
26
27
28 // RK: should be using snprintf actually... (or stringstream)
29 ANTLR_C_USING(sprintf)
30
31 ANTLR_USE_NAMESPACE(std)string operator+( const ANTLR_USE_NAMESPACE(std)string& lhs, const int rhs )
32 {
33 char tmp[100];
34 sprintf(tmp,"%d",rhs);
35 return lhs+tmp;
36 }
37
38 ANTLR_USE_NAMESPACE(std)string operator+( const ANTLR_USE_NAMESPACE(std)string& lhs, size_t rhs )
39 {
40 char tmp[100];
41 sprintf(tmp,"%lu",(unsigned long)rhs);
42 return lhs+tmp;
43 }
44
45 /** Convert character to readable string
46 */
47 ANTLR_USE_NAMESPACE(std)string charName(int ch)
48 {
49 if (ch == EOF)
50 return "EOF";
51 else
52 {
53 ANTLR_USE_NAMESPACE(std)string s;
54
55 // when you think you've seen it all.. an isprint that crashes...
56 ch = ch & 0xFF;
57 #ifdef ANTLR_CCTYPE_NEEDS_STD
58 if( ANTLR_USE_NAMESPACE(std)isprint( ch ) )
59 #else
60 if( isprint( ch ) )
61 #endif
62 {
63 s.append("'");
64 s += ch;
65 s.append("'");
66 // s += "'"+ch+"'";
67 }
68 else
69 {
70 s += "0x";
71
72 unsigned int t = ch >> 4;
73 if( t < 10 )
74 s += t | 0x30;
75 else
76 s += t + 0x37;
77 t = ch & 0xF;
78 if( t < 10 )
79 s += t | 0x30;
80 else
81 s += t + 0x37;
82 }
83 return s;
84 }
85 }
86
87 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
88 }
89 #endif
90