[vConnect/trunk/stand2.0] added: InputStream; modified: TextInputStream, InputStreamを継承するよう修正
@@ -37,7 +37,7 @@ | ||
37 | 37 | |
38 | 38 | TextInputStream reader( otoIni, "Shift_JIS" ); |
39 | 39 | TextOutputStream writer( (dstDir_s + "oto.ini").c_str(), "Shift_JIS", "\x0D\x0A" ); |
40 | - while( false == reader.isEOF() ){ | |
40 | + while( reader.ready() ){ | |
41 | 41 | string buffer = reader.readLine(); |
42 | 42 | if( buffer.length() == 0 ){ |
43 | 43 | continue; |
@@ -12,7 +12,7 @@ | ||
12 | 12 | { |
13 | 13 | TextInputStream reader( "fixture/TextInputStream/shift_jis_crlf.txt", "Shift_JIS" ); |
14 | 14 | |
15 | - CPPUNIT_ASSERT( false == reader.isEOF() ); | |
15 | + CPPUNIT_ASSERT( true == reader.ready() ); | |
16 | 16 | |
17 | 17 | string actual; |
18 | 18 | string expected; |
@@ -20,35 +20,38 @@ | ||
20 | 20 | expected = "だ・い・じ・け・ん"; |
21 | 21 | CPPUNIT_ASSERT_EQUAL( expected, actual ); |
22 | 22 | |
23 | - CPPUNIT_ASSERT( false == reader.isEOF() ); | |
23 | + CPPUNIT_ASSERT( true == reader.ready() ); | |
24 | 24 | |
25 | 25 | actual = reader.readLine(); |
26 | 26 | expected = "社会復帰できなくなっちゃうよ"; |
27 | 27 | CPPUNIT_ASSERT_EQUAL( expected, actual ); |
28 | 28 | |
29 | - CPPUNIT_ASSERT( true == reader.isEOF() ); | |
29 | + CPPUNIT_ASSERT( false == reader.ready() ); | |
30 | 30 | } |
31 | 31 | |
32 | 32 | void testTextInputStreamUTF8() |
33 | 33 | { |
34 | - TextInputStream reader( "fixture/TextInputStream/utf8_lf.txt", "UTF-8" ); | |
34 | + TextInputStream *textInputStream = new TextInputStream( "fixture/TextInputStream/utf8_lf.txt", "UTF-8" ); | |
35 | + InputStream *reader = (InputStream *)textInputStream; | |
35 | 36 | |
36 | - CPPUNIT_ASSERT( false == reader.isEOF() ); | |
37 | + CPPUNIT_ASSERT( true == reader->ready() ); | |
37 | 38 | |
38 | 39 | string actual; |
39 | 40 | string expected; |
40 | 41 | |
41 | - CPPUNIT_ASSERT( false == reader.isEOF() ); | |
42 | - actual = reader.readLine(); | |
42 | + CPPUNIT_ASSERT( true == reader->ready() ); | |
43 | + actual = reader->readLine(); | |
43 | 44 | expected = "吾輩は猫である。名前はまだ無い。"; |
44 | 45 | CPPUNIT_ASSERT_EQUAL( expected, actual ); |
45 | 46 | |
46 | - CPPUNIT_ASSERT( false == reader.isEOF() ); | |
47 | - actual = reader.readLine(); | |
47 | + CPPUNIT_ASSERT( true == reader->ready() ); | |
48 | + actual = reader->readLine(); | |
48 | 49 | expected = "どこで生れたかとんと見当がつかぬ。"; |
49 | 50 | CPPUNIT_ASSERT_EQUAL( expected, actual ); |
50 | 51 | |
51 | - CPPUNIT_ASSERT( true == reader.isEOF() ); | |
52 | + CPPUNIT_ASSERT( false == reader->ready() ); | |
53 | + | |
54 | + delete textInputStream; | |
52 | 55 | } |
53 | 56 | |
54 | 57 | CPPUNIT_TEST_SUITE( TextInputStreamTest ); |
@@ -1,3 +1,3 @@ | ||
1 | 1 | all: *.cpp *.h |
2 | - g++ -finput-charset=UTF-8 AllTests.cpp ../../libiconv-1.13/lib/*.o -lcppunit -o run | |
2 | + g++ -finput-charset=UTF-8 AllTests.cpp ../../libiconv-1.13/lib/*.o -lcppunit -o run | |
3 | 3 | ./run |
@@ -1,3 +1,16 @@ | ||
1 | +/* | |
2 | + * EncodingConverter.h | |
3 | + * Copyright © 2012 kbinani | |
4 | + * | |
5 | + * This file is part of vConnect-STAND. | |
6 | + * | |
7 | + * vConnect-STAND is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GPL License. | |
9 | + * | |
10 | + * vConnect-STAND is distributed in the hope that it will be useful, | |
11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
13 | + */ | |
1 | 14 | #ifndef __EncodingConverter_h__ |
2 | 15 | #define __EncodingConverter_h__ |
3 | 16 |
@@ -16,6 +16,7 @@ | ||
16 | 16 | |
17 | 17 | #include <stdio.h> |
18 | 18 | #include "EncodingConverter.h" |
19 | +#include "InputStream.h" | |
19 | 20 | |
20 | 21 | namespace vconnect |
21 | 22 | { |
@@ -23,7 +24,7 @@ | ||
23 | 24 | * テキストファイルを読み込むためのクラス |
24 | 25 | * @todo 1 行が BUFFER_SIZE を超えるテキストを読む場合動作がデタラメ |
25 | 26 | */ |
26 | - class TextInputStream | |
27 | + class TextInputStream : public InputStream | |
27 | 28 | { |
28 | 29 | private: |
29 | 30 | /** |
@@ -159,12 +160,12 @@ | ||
159 | 160 | } |
160 | 161 | |
161 | 162 | /** |
162 | - * ファイル読み込みがファイル末尾に達したかどうか | |
163 | - * @return ファイル末尾に達している場合 true を、そうでなければ false を返す。 | |
163 | + * ストリームに対してさらに読み込めるかどうか | |
164 | + * @return 読み込める状態であれば true を返す | |
164 | 165 | */ |
165 | - bool isEOF() | |
166 | + bool ready() | |
166 | 167 | { |
167 | - return feof( this->fileHandle ) ? true : false; | |
168 | + return feof( this->fileHandle ) ? false : true; | |
168 | 169 | } |
169 | 170 | |
170 | 171 | /** |