source: cfg_oil/trunk/toppers/cpp.cpp@ 8

Last change on this file since 8 was 8, checked in by msugi, 13 years ago

ディレクトリ構造の作成,ソース一式とReleaseビルドのコミット.

File size: 5.6 KB
Line 
1/*
2 * TOPPERS Software
3 * Toyohashi Open Platform for Embedded Real-Time Systems
4 *
5 * Copyright (C) 2007-2008 by TAKAGI Nobuhisa
6 *
7 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
8 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
9 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
10 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
11 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
12 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
13 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
14 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
15ƒƒ“ƒgi—˜—p
16 * ŽÒƒ}ƒjƒ…
17ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
18 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
19 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
20 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
21 * ‚ƁD
22 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
23ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
24ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
25 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
26 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
27 * •ñ‚·‚邱‚ƁD
28 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
29 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
30 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
31 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
32 * –Ɛӂ·‚邱‚ƁD
33 *
34 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
35 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
36 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
37 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
38 * ‚̐ӔC‚𕉂í‚È‚¢D
39 *
40 */
41#include <cctype>
42#include <cstring>
43#include <cstdio>
44#include <stdexcept>
45#include "toppers/cpp.hpp"
46
47namespace toppers
48{
49
50 /*!
51 * \brief “ñdˆø—p•„‚ň͂܂ꂽ•¶Žš—ñ‚ð“WŠJ‚·‚éB
52 */
53 std::string expand_quote( std::string const& str )
54 {
55 // boost-1.35.xˆÈã‘΍ô
56 std::string::size_type n = str.find_first_not_of( " \t\r\n" );
57 std::string quoted( str, n );
58
59 if ( quoted.empty() || quoted[0] != '"' || quoted[quoted.size() - 1] != '"' )
60 {
61 throw std::invalid_argument( "argument is not quoted" );
62 }
63 std::string result;
64 for ( std::string::const_iterator iter( quoted.begin() + 1 ), last( quoted.end() - 1 );
65 iter != last;
66 ++iter )
67 {
68 if ( *iter == '\\' )
69 {
70 if ( ++iter == last )
71 {
72 throw std::invalid_argument( "argument is not quoted" );
73 }
74 char c = *iter;
75 switch ( c )
76 {
77 case 'a':
78 c = '\a';
79 break;
80 case 'b':
81 c = '\b';
82 break;
83 case 'f':
84 c = '\f';
85 break;
86 case 'n':
87 c = '\n';
88 break;
89 case 'r':
90 c = '\r';
91 break;
92 case 't':
93 c = '\t';
94 break;
95 case 'v':
96 c = '\v';
97 break;
98 case 'x':
99 if ( std::isxdigit( static_cast< unsigned char >( *iter ) ) )
100 {
101 c = 0;
102 for ( std::string::const_iterator bound( iter + 2 );
103 iter != bound && std::isxdigit( static_cast< unsigned char >( *iter ) );
104 ++iter )
105 {
106 c <<= 4;
107 int t = std::tolower( static_cast< unsigned char >( *iter ) );
108 static char const xdigits[] = "0123456789abcdef";
109 c += std::strchr( xdigits, t ) - xdigits;
110 }
111 }
112 break;
113 default:
114 if ( '0' <= c && c <= '7' ) // '\ooo'
115 {
116 c = 0;
117 for ( std::string::const_iterator bound( iter + 3 );
118 iter != bound && ( '0' <= *iter && *iter <= '7' );
119 ++iter )
120 {
121 c = ( c << 3 ) + *iter - '0';
122 }
123 }
124 // ‘Û•¶Žš–¼i\uhhhh, \Uhhhhhhhhj–¢‘Ήž
125 // “ñ•¶Žš•\‹Li<:“™j–¢‘Ήž
126 // ŽO•¶Žš•\‹Li??/“™j–¢‘Ήž
127 break;
128 }
129 result.push_back( c );
130 }
131 else
132 {
133 result.push_back( *iter );
134 }
135 }
136 return result;
137 }
138
139 /*!
140 * \brief •¶Žš—ñ‚Å“ñdˆø—p•„‚ň͂Þ
141 */
142 std::string quote_string( std::string const& str )
143 {
144 std::string result;
145 result.reserve( str.size() + 2 );
146
147 result.push_back( '"' ); // open
148
149 for ( std::string::const_iterator iter( str.begin() ), last( str.end() );
150 iter != last;
151 ++iter )
152 {
153 switch ( char c = *iter )
154 {
155 case '\'':
156 result += "\\\'";
157 break;
158 case '\"':
159 result += "\\\"";
160 break;
161 case '\0':
162 result += "\\0";
163 break;
164 case '\a':
165 result += "\\a";
166 break;
167 case '\b':
168 result += "\\b";
169 break;
170 case '\f':
171 result += "\\f";
172 break;
173 case '\n':
174 result += "\\n";
175 break;
176 case '\r':
177 result += "\\r";
178 break;
179 case '\t':
180 result += "\\t";
181 break;
182 case '\v':
183 result += "\\v";
184 break;
185 case '\\':
186 // SJIS–¢‘Ήž
187 result.push_back( c );
188 result.push_back( c );
189 break;
190 default:
191 result.push_back( c );
192 break;
193 }
194 }
195
196 result.push_back( '"' ); // close
197
198 return result;
199 }
200
201}
Note: See TracBrowser for help on using the repository browser.