OSDN Git Service

lexerに関係するソースをsrc/lexer配下に移動。
authorderui <derutakayu@user.sourceforge.jp>
Fri, 11 Dec 2009 16:57:40 +0000 (01:57 +0900)
committerderui <derutakayu@user.sourceforge.jp>
Fri, 11 Dec 2009 16:57:40 +0000 (01:57 +0900)
utakataで標準的に利用するための例外のメッセージはunicode::UniStringを利用するように。
sublexerで定義していたlexerを、ソース分けに基いてそれぞれ単独のファイルに分割。
textarrayformatのテストを追加。

38 files changed:
.gitignore
config.log
src/Makefile.in
src/common/textarrayformat.cpp
src/common/textarrayformat.h
src/delimiter.cpp [deleted file]
src/exception.h
src/exception_macro.h
src/exception_std.h
src/file_reader.cpp
src/lexer/charactor_lexer.cpp [new file with mode: 0755]
src/lexer/charactor_lexer.h [new file with mode: 0755]
src/lexer/delimiters.cpp [new file with mode: 0755]
src/lexer/delimiters.h [moved from src/delimiter.h with 50% similarity]
src/lexer/lexer_dispatcher.cpp [moved from src/lexer_dispatcher.cpp with 100% similarity]
src/lexer/lexer_dispatcher.h [moved from src/lexer_dispatcher.h with 99% similarity]
src/lexer/lexer_interface.h [moved from src/lexer_interface.h with 69% similarity]
src/lexer/number_lexer.cpp [moved from src/number_lexer.cpp with 100% similarity]
src/lexer/number_lexer.h [moved from src/number_lexer.h with 100% similarity]
src/lexer/scheme_lexer.cpp [moved from src/scheme_lexer.cpp with 100% similarity]
src/lexer/scheme_lexer.h [moved from src/scheme_lexer.h with 67% similarity]
src/lexer/string_lexer.cpp [new file with mode: 0755]
src/lexer/string_lexer.h [new file with mode: 0755]
src/lexer/sublexer_impl.cpp [moved from src/sublexer_impl.cpp with 100% similarity]
src/reader_interface.h
src/string_reader.cpp
src/test/Makefile
src/test/Makefile.am
src/test/Makefile.in
src/test/encoding_reader_test.cpp
src/test/file_reader_test.cpp
src/test/textarrayformat_test.cpp
src/test/type_test.cpp
src/test/utf8_transcoder_test.cpp
src/transcoder_interface.h
src/type.cpp
src/type.h
src/unicode.h

index 8986cb2..92b5a20 100644 (file)
@@ -44,3 +44,4 @@ utakata
 /src/test/OMakefile.omc
 /src/test/encoding_reader_test
 /src/test/file_reader_test
+/src/test/test.txt
index 47d4491..1fd65c4 100644 (file)
@@ -573,515 +573,9 @@ generated by GNU Autoconf 2.63.  Invocation command line was
   CONFIG_HEADERS  = 
   CONFIG_LINKS    = 
   CONFIG_COMMANDS = 
-  $ ./config.status Makefile
-
-on vaio_z
-
-config.status:777: creating Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile
-
-on vaio_z
-
-config.status:777: creating src/Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status Makefile
-
-on vaio_z
-
-config.status:777: creating Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile
-
-on vaio_z
-
-config.status:777: creating src/Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status Makefile
-
-on vaio_z
-
-config.status:777: creating Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile
-
-on vaio_z
-
-config.status:777: creating src/Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status Makefile
-
-on vaio_z
-
-config.status:777: creating Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile
-
-on vaio_z
-
-config.status:777: creating src/Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
   $ ./config.status src/test/Makefile depfiles
 
 on vaio_z
 
 config.status:777: creating src/test/Makefile
 config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status Makefile
-
-on vaio_z
-
-config.status:777: creating Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile
-
-on vaio_z
-
-config.status:777: creating src/Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile
-
-on vaio_z
-
-config.status:777: creating src/Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status Makefile
-
-on vaio_z
-
-config.status:777: creating Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile
-
-on vaio_z
-
-config.status:777: creating src/Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status Makefile
-
-on vaio_z
-
-config.status:777: creating Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile
-
-on vaio_z
-
-config.status:777: creating src/Makefile
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/test/Makefile depfiles
-
-on vaio_z
-
-config.status:777: creating src/test/Makefile
-config.status:1051: executing depfiles commands
-
-## ---------------------- ##
-## Running config.status. ##
-## ---------------------- ##
-
-This file was extended by utakata config.status 0.0.1, which was
-generated by GNU Autoconf 2.63.  Invocation command line was
-
-  CONFIG_FILES    = 
-  CONFIG_HEADERS  = 
-  CONFIG_LINKS    = 
-  CONFIG_COMMANDS = 
-  $ ./config.status src/Makefile
-
-on vaio_z
-
-config.status:777: creating src/Makefile
index f7129fc..d5eed76 100644 (file)
@@ -93,6 +93,7 @@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
 PACKAGE_NAME = @PACKAGE_NAME@
 PACKAGE_STRING = @PACKAGE_STRING@
 PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
 SET_MAKE = @SET_MAKE@
index 46a73b6..dcbfe83 100644 (file)
@@ -1,87 +1,40 @@
 #include <vector>
 #include <string>
-#include <sstream>
-
-#include <iostream>
-#include <exception>
-#include <assert.h>
-
-
 #include "textarrayformat.h"
 
-using namespace std;
-
-textarrayformat::TextArrayReader::TextArrayReader(std::istream& is) :
-    splitter_(), blocks_()
-{
-    // openを利用して読出す。
-    // openは例外を返す可能性がある。
-    open(is);
-}
-
-void textarrayformat::TextArrayReader::open(std::istream& is)
-{
-    // isより行単位での読み出しを行う。
-
-    std::string tmp;
-    if (!std::getline(is, tmp))
-    {
-        // 最初の一行が取得できない場合、これは失敗とする。
-        throw "can't get splitter line";
-    }
-
-    // スプリッタとして設定させる。
-    splitter_ = tmp;
-
-    std::string block;
-    while (getline(is, tmp)) {
-        // 取得していく。
-        if (splitter_ != tmp)
-        {
-            //スプリッタ以外の場合はまとめる。
-            block += tmp + "\n";
-        }
-        else
-        {
-            this->blocks_.push_back(block);
-            block.clear();
-        }
-    }
-
-    // 最後に殘っている場合があるのでこうしておく。
-    if (!block.empty())
-    {
-        this->blocks_.push_back(block);
-    }
-}
-
-std::string textarrayformat::TextArrayReader::get(int num)
-{
-    // ここはassertではなく、通常の例外によるチェックを行う。
-    if (num < 0)
-    {
-        throw textarrayformat::OutOfIndexException("Argument must be greater than zero");
-    }
-
-    if (static_cast<size_t>(num) >= blocks_.size())
-    {
-        std::stringstream ss;
-        ss << "Argument must be less than blocks num : size [" << blocks_.size()
-           << "] and receive value is [" << num << "]" << endl;
-            
-        throw textarrayformat::OutOfIndexException(ss.str());
-    }
+namespace textarrayformat = utility::textarrayformat;
 
-    // 本当はここでatにしておけば、事前のチェックは必要無いはず。
-    return blocks_[num];
+// 宣言のコメントを参照してください。
+void textarrayformat::TextArrayGenerator::Append(const std::string& parts) {
+  if (parts == separator_) {
+    construct_text_ += now_block_ + separator_;
+    now_block_.clear();
+  } else {
+    now_block_ += parts + "\n";
+  }
 }
 
-textarrayformat::OutOfIndexException::OutOfIndexException(const std::string& str) :
-    str_(str)
-{
+// 宣言のコメントを参照してください。
+void textarrayformat::TextArrayGenerator::Punctuate() {
+  construct_text_ += now_block_ + separator_;
+  now_block_.clear();
 }
 
-const char* textarrayformat::OutOfIndexException::what() const throw()
-{
-    return str_.c_str();
+// 宣言のコメントを参照してください。
+void textarrayformat::TextArrayReader::SplitBlock(
+    const textarrayformat::TextArrayGenerator& generator) {
+  std::string separator = generator.separator();
+  const std::string& all_text = generator.construct_text().substr(
+      separator.size());
+
+  size_t pos = std::string::npos;
+  size_t begin = 0;
+  while ((pos = all_text.find(separator, begin + 1)) != std::string::npos) {
+    text_blocks_.push_back(all_text.substr(begin, pos - begin));
+    begin += pos + separator.size();
+  }
+
+  if (begin < all_text.size()) {
+    text_blocks_.push_back(all_text.substr(begin));
+  }
 }
index 231480f..32b39e2 100644 (file)
 // TextArrayFormatは、TextArrayGeneratorにて文字列からの生成を行い
 // TextArrayReaderによって、テキストブロックを取得することができます。
 // 
-// ã\81\93ã\82\8cã\82\89ã\81¯柔軟に行うことができるため、テキストを扱うテストデータを
+// ã\81\93ã\82\8cã\82\89ã\82\92柔軟に行うことができるため、テキストを扱うテストデータを
 // 複数作成したい場合に有用です。
 #ifndef _UTAKATA_SRC_COMMON_TEXTARRAYFORMAT_H_
 #define _UTAKATA_SRC_COMMON_TEXTARRAYFORMAT_H_
 
 #include <string>
 #include <vector>
-#include <exception>
+#include "src/common/scoped_ptr.h"
 
 namespace utility {
 
 namespace textarrayformat {
 
+class TextArrayGenerator {
+  // 渡された文字列から、TextArrayFormatとなるような文字列のブロックを
+  // 作成します。
+  // あくまでTextArrayFormatのデータをGenerateするだけなので、読み込み媒体
+  // は問いません。
+ public:
+  explicit TextArrayGenerator(const std::string& separator)
+      : separator_(separator), now_block_(), construct_text_() {
+    construct_text_ = separator + "\n";
+    separator_ += "\n";
+  }
+  TextArrayGenerator(const TextArrayGenerator& generator)
+      : separator_(generator.separator_),
+        now_block_(generator.now_block_),
+        construct_text_(generator.construct_text_) {}
+  virtual ~TextArrayGenerator() {}
+
+  // 文字列をブロックとして追加します。渡された文字列がseparatorと一致する
+  // 場合、その時点まで追加された文字列がブロックとして設定されます。
+  // ブロックとして追加された場合、次に追加された文字列は新しい文字列と
+  // されます。
+  // ここで追加されたデータは、ブロック中の一行として取り扱われ、末尾
+  // に改行が付与されます。
+  // ここでの改行は\nで固定とされます。
+  void Append(const std::string& parts);
+
+  // 現在のブロックを、一つのブロックとして強制的に区切ります。
+  // 区切りにはseparatorが利用されます。ブロックが空文字であっても、
+  // 空文字のブロックとして登録が行われます。
+  void Punctuate();
+
+  // 構築済の文字列を返します。ここで返される文字列は、
+  // 先頭行がseparatorであり、それ以降の各ブロックがseparator行で
+  // 区切られたブロックとなっています。
+  const std::string& construct_text() const {return construct_text_;}
+
+  // 初期設定されたseparatorを返します。
+  const std::string& separator() const {return separator_;}
+
+ private:
+  // 生成するTextArrayFormatのセパレータです。
+  std::string separator_;
+
+  // 現在構築中のブロック文字列です。
+  std::string now_block_;
+
+  // 最終的にTextArrayReaderに渡されるブロック文字列です。
+  // この文字列については追加のみが行われます。
+  std::string construct_text_;
+};
+
 class TextArrayReader {
+  // TextArrayGeneratorから取得した構築済文字列を元に、
+  // text arrayを読み出して作成します。
  public:
 
-  explicit TextArrayReader(const TextArrayGenerator& is);
+  explicit TextArrayReader(const TextArrayGenerator& generator) {
+    SplitBlock(generator);
+  }
+
   virtual ~TextArrayReader() {}
 
-  // 指定したストリームの先頭からフォーマットに従ってブロック単位
-  // への切り出しを行う。
-  // この関数が成功した場合、以前のブロックなどは保存されない。
-  void open(std::istream& is);
+  // 指定した位置のテキストブロックを取得します。
+  // ここで取得されるテキストブロックは、改行などもそのまま付与されている
+  // 形式になります。
+  // posの指定が不正である場合、std::out_of_range例外が送出されます。
+  const std::string& GetBlockAt(int pos) const {return text_blocks_.at(pos);}
 
-  // 指定したブロックを取得する。
-  // 番号を指定しない場合には、最初に取得したブロックが取得される
-  std::string get(int = 0);
+  // 分解されたブロックのリストを取得します。ブロックのリストには
+  // splitterは存在しません
+  const std::vector<std::string>& text_blocks() const {return text_blocks_;}
 
-  // ブロックのリストを取得する。
-  const std::vector<std::string>& getBlock() const {return blocks_;}
+  // Generatorから取得した構築済ブロック文字列を、それぞれのブロック文字列に
+  // 分解します。Generatorが変化しない限り、何度実行しても同一の結果が
+  // 得られます。
+  void SplitBlock(const TextArrayGenerator& generator);
 
  private:
 
-  // ファイル中のスプリッタを行ごと退避する
-  std::string splitter_;
+  // Generatorで構築されたブロック文字列です
+  std::string construct_text_;
 
-  // テキストのブロックを退避しておくリスト
-  std::vector<std::string> blocks_;
+  // Generatorより取得したテキストを単位で保持します。
+  std::vector<std::string> text_blocks_;
 };
 
 };
diff --git a/src/delimiter.cpp b/src/delimiter.cpp
deleted file mode 100755 (executable)
index 5b7206f..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-#include "delimiter.h"
-#include "reader.h"
-#include "unicode.h"
-
-using namespace utakata::lexer_delimiter;
-
-bool Normal::operator()(const utakata::unicode::UniChar& ch)
-{
-    // 渡された文字がデリミタかどうかを返す。
-        // 渡された文字がデリミタかどうかを判別する。
-    // このクラスガ判別するデリミタは、
-    // <delimiter> - ( | ) | [ | ] | " | ; | #
-    //          | <whitespace>
-    // <whitespace> - <character tabulation>
-    //          | <linefeed> | <line tabulation> | <form feed>
-    //          | <carriage return> | <next line>
-    //          | <any character whose category is Zs, Zl, or Zp>
-    // に該当するデリミタ。
-    // このデリミタは、<boolean>,<string>,<number>, .<character>
-    // を解析している間に出現するものであり、それ以外の場合は、
-    // デリミタとして読み飛ばしてはならない。
-
-    switch (ch.getRawCode())
-    {
-    case '(':
-    case '[':
-    case ')':
-    case ']':
-    case '"':
-    case ';':
-    case '#':
-        return true;
-    default:
-        // それ以外の場合、whitespaceである可能正があるため、そちらはそちら
-        // で読みとばす。
-        return Whitespace()(ch);
-    }
-}
-
-bool Whitespace::operator()(const utakata::unicode::UniChar& ch)
-{
-    switch (ch.getRawCode())
-    {
-    case '\r':                  // carriage return 復帰
-    case '\n':                  // linefeed  改行
-    case ' ':                   // space 空白
-    case '\t':                  // tab タブ
-    case '\v':                  // vertical tab 垂直タブ
-    case '\f':                  // page 改ページ
-        return true;
-    default:
-        return false;
-    }
-}
-
-bool LineEnding::operator()(const utakata::unicode::UniChar& ch,
-                            smart_ptr<utakata::reader::StreamReader>& strm)
-{
-    // 今の文字と、次の文字とを利用してチェックする。
-    switch (ch.getRawCode())
-    {
-    case '\n': return true;
-    case '\r':
-        //次の文字が必要になる。
-    {
-        utakata::unicode::UniChar ch2(strm->peek());
-        if (ch2.getRawCode() == '\n')
-        {
-            strm->read();
-        }
-        return true;
-    }
-    default:
-        return false;
-    }
-}
-
-bool HexValue::operator()(const utakata::unicode::UniChar& ch)
-{
-    if (ch.getRawCode() >= 'a' && ch.getRawCode() <= 'f')
-    {
-        return true;
-    }
-    else if (ch.getRawCode() >= 'A' && ch.getRawCode() <= 'F')
-    {
-        return true;
-    }
-
-    // 最後に数値だけの判定を返す。
-    return utakata::unicode::is_numeric(ch);
-}
-
-bool String::operator()(const utakata::unicode::UniChar& ch)
-{
-    if (ch.getRawCode() == '"')
-    {
-        return true;
-    }
-    return false;
-}
-
-bool Prefix::operator()(const utakata::unicode::UniString& str)
-{
-    if (str.size() <= 2)
-    {
-        return false;
-    }
-    
-    utakata::unicode::UniChar s = str[0];
-    utakata::unicode::UniChar s1 = str[1];
-    if (s.getRawCode() == '#' && (s1 == 'b' || s1 == 'B' ||
-                                  s1 == 'o' || s1 == 'O' ||
-                                  s1 == 'x' || s1 == 'X' || 
-                                  s1 == 'd' || s1 == 'D')
-        )
-    {
-        return true;
-    }
-    return false;
-}
-
-bool Exactness::operator()(const utakata::unicode::UniString& str)
-{
-    if (str.size() <= 2)
-    {
-        return false;
-    }
-    
-    utakata::unicode::UniChar s = str[0];
-    utakata::unicode::UniChar s1 = str[1];
-
-    if (s.getRawCode() == '#' && (s1 == 'i' || s1 == 'I' ||
-                                  s1 == 'e' || s1 == 'E')
-        )
-    {
-        return true;
-    }
-    return false;
-}
index 806ad1b..f2f1150 100755 (executable)
 // は自動的に設定されることが無いため、適宜exception::Exceptionと同一順の
 // 引数を宣言し、superクラスのコンストラクタを呼ぶ必要があります。
 //
+// Exceptionより派生した例外は、whatから自身の名前を返すように実装
+// しなければなりません。
+//
 // example
 // -------
 // // 派生クラスの定義例
 // #include "src/exception.h"
 // class HogeException : public Exception {
 //  public:
-//   HogeException(const std::string& message,
+//   HogeException(const unicode::UniString& message,
 //                 const exception::ExceptionInfo& info) :
 //       Exception(message, info) {}
 //
 //   HogeException(const Exception& prev,
-//                 const std::string& message,
+//                 const unicode::UniString& message,
 //                 const exception::ExceptionInfo& info) :
 //       Exception(prev, message, info) {}
 // };
 #include "src/common/smart_ptr.h"
 
 namespace utakata {
+
+namespace unicode {
+class UniString;
+}
+
 namespace exception {
 
 struct ExceptionInfo {
@@ -82,21 +90,22 @@ class Exception : public std::exception {
 
   // 前回送出された例外が存在しない場合のコンストラクタです。
   // すべての値が指定されることが必須となります。
-  Exception(const std::string& message, const ExceptionInfo& info) :
+  Exception(const unicode::UniString& message, const ExceptionInfo& info) :
       previous_exception_(), message_(message), info_(info) {}
 
   // 前回送出された例外を記録します。
-  Exception(const Exception& prev, const std::string& message,
+  Exception(const Exception& prev, const unicode::UniString& message,
             const ExceptionInfo& info) :
-      previous_exception_(new Exception(prev)), message_(message),
+      previous_exception_(new Exception(prev)),
+      message_(new unicode::UniString(message)),
       info_(info) {}
   virtual ~Exception() throw() {}
 
   // message_の内容を表示します。
-  virtual const char* what() const throw() {return message_.c_str();}
+  virtual const char* what() const throw() {return "Exception";}
 
   // 例外に設定されたメッセージを取得します。
-  const std::string& message() const {return message_;}
+  const unicode::UniString& message() const {return *message_;}
 
   // 例外情報構造体を返します。
   const ExceptionInfo& info() const {return info_;}
@@ -116,7 +125,7 @@ class Exception : public std::exception {
   utility::smart_ptr<Exception> previous_exception_;
 
   // 例外のメッセージが渡されます。
-  const std::string message_;
+  utility::smart_ptr<unicode::UniString> message_;
 
   // 例外の基本情報を保持した構造体です。
   ExceptionInfo info_;
index 53c028c..6eef2b7 100644 (file)
   throw EXCEPTION(prev, message, utakata::exception::ExceptionInfo( \
       __FILE__, __func__, __LINE__))
 
+// exception::Exceptionに、別の例外を添付して送出します。
+// 特殊化した例外に不要なコンストラクタを付加したくない時に有効です。
+#define THROW_WRAPED_EXCEPTION_(prev, message)                          \
+  throw utakata::exception::Exception(                                  \
+      prev, message, utakata::exception::ExceptionInfo(                 \
+          __FILE__, __func__, __LINE__))
+
 #endif /* _UTAKATA_SRC_EXCEPTION_MACRO_H_ */
 
index 783397f..f2bde22 100644 (file)
 #include "src/exception.h"
 
 namespace utakata {
+
+namespace unicode {
+class UniString;
+}
+
 namespace exception {
 
 class NullException : public exception::Exception {
   // NULLであることが想定外である場合に送出される例外です。
  public:
-  NullException(const std::string& message, const ExceptionInfo& info) :
+  NullException(const unicode::UniString& message, const ExceptionInfo& info) :
       Exception(message, info) {}
 
-  // 前回送出された例外を記録します。
-  NullException(const Exception& prev, const std::string& message,
+  NullException(const Exception& prev, const unicode::UniString& message,
             const ExceptionInfo& info) :
       Exception(prev, message, info) {}
 
-  // message_の内容を表示します。
-  virtual const char* what() const throw() {
-    return std::string("NullException : " + message()).c_str();
-  }
+  virtual const char* what() const throw() {return "NullException";}
 };
 
 class OutOfRangeException : public exception::Exception {
   // 引数などが範囲外である場合などに送出される例外です。
  public:
-  OutOfRangeException(const std::string& message, const ExceptionInfo& info) :
-      Exception(message, info) {}
+  OutOfRangeException(const unicode::UniString& message,
+                      const ExceptionInfo& info)
+      : Exception(message, info) {}
 
-  // 前回送出された例外を記録します。
-  OutOfRangeException(const Exception& prev, const std::string& message,
-            const ExceptionInfo& info) :
-      Exception(prev, message, info) {}
+  OutOfRangeException(const Exception& prev, const unicode::UniString& message,
+                      const ExceptionInfo& info)
+      : Exception(prev, message, info) {}
 
-  // message_の内容を表示します。
-  virtual const char* what() const throw() {
-    return std::string("OutOfRangeException : " + message()).c_str();
-  }
+  virtual const char* what() const throw() {return "OutOfRangeException";}
 };
+
 }
 }
 
index 69fc230..f96065b 100755 (executable)
@@ -83,8 +83,10 @@ std::vector<unsigned int> reader::FileReader::Read(size_t num) {
     return std::vector<unsigned int>();
   }
 
+  std::vector<unsigned char> byte(num + 1, 0);
+  int readed = ::fread(&byte[0], 1, num, file_pointer_);
   std::vector<unsigned int> ret(num + 1, 0);
-  int readed = ::fread(&ret[0], 1, num, file_pointer_);
+  std::copy(byte.begin(), byte.end(), ret.begin());
 
   pos_ += readed;
 
diff --git a/src/lexer/charactor_lexer.cpp b/src/lexer/charactor_lexer.cpp
new file mode 100755 (executable)
index 0000000..7475198
--- /dev/null
@@ -0,0 +1,103 @@
+#include "src/exception_macro.h"
+#include "src/lexer/charactor_lexer.h"
+#include "src/lexer/delimiters.h"
+#include "src/lexeme.h"
+
+namespace lexer = utakata::lexer;
+namespace delimiter = utakata::lexer_delimiter;
+
+// 宣言のコメントを参照してください。
+bool lexer::CharactorDispatchTerm::IsDispatch(
+    const unicode::UniString& string) const {
+  if (ch.size() >= 2 && ch.At(0).rawcode() == '#' &&
+      ch.At(1).rawcode() == '\\') {
+    return true;
+  }
+
+  return false;
+}
+
+// 宣言のコメントを参照してください。
+bool lexer::CharactorNames::IsCharactorName(const unicode::UniString& string) {
+  
+}
+
+unsigned int lexer::CharactorNames::GetCodeFromCharactorName(
+    const unicode::UniString& string) {
+
+}
+
+// 宣言のコメントを参照してください。
+lexeme::ILexeme* lexer::CharactorLexer::Lex(const unicode::UniString& string.
+                                            reader::EncodingReader* reader) {
+  unicode::UniChar charactor(reader->Read());
+  bool hex_flag = (charactor.rawcode() == 'x' ? true : false);
+
+  unicode::UniString str();
+  delimiter::StarndardDelimiterChecker std_delimiter();
+  delimiter::HexValueChecker hex_checker();
+
+  while (!reader->IsEof()) {
+    unicode::UniChar tmp(reader->Peek());
+
+    if (std_delimiter(tmp)) {
+      break;
+    } else if (hex_flag && !hex_checker(tmp)) {
+      THROW_EXCEPTION_(lexer::LexException, 
+                       unicode::Convert(
+                           "hex value is 0-9a-fA-F only : ").Append(tmp));
+    }
+
+    str.Append(unicode::UniChar(reader->Read()));
+  }
+
+  if (str.IsEmpty()) {
+    THROW_EXCEPTION_(lexer::LexException,
+                     unicode::Convert(
+                         "Charactor must have to 1 or more Charactors"));
+  }
+
+  UniChar parsed_charactor();
+  if (hex_flag) {
+    ConvertHexValueToCode(str, &parsed_charactor);
+  } else if (str.size() > 1) {
+    ConvertCharactorNameToCode(str, &parsed_charactor);
+  } else {
+    parsed_charactor = unicode::UniChar(str.At(0));
+  }
+
+  return lexeme::CharactorLexeme(parsed_charactor);
+}
+
+// 宣言のコメントを参照してください。
+void lexer::CharactorLexer::ConvertCharactorNameToCode(
+    const unicode::UniString& string, unicode::UniChar* code) {
+  if (!lexer::CharactorNames::IsCharactorName(string)) {
+    THROW_EXCEPTION_(lexer::LexException,
+                     unicode::Convert(
+                         "Invalid Charactor Name : ").Append(string));
+  }
+
+  *code = unicode::UniChar(
+      lexer::CharactorNames::GetCodeFromCharactorName(string));
+}
+
+// 宣言のコメントを参照してください。
+void lexer::CharactorLexer::ConvertHexValueToCode(
+    const unicode::UniString& string, unicode::UniChar* code) {
+  unicode::UniString::const_iterator begin = string.begin(),
+      end = string.end();
+
+  unsigned int code_merge = 0;
+  for (int i = string.GetSize(); begin != end; ++i, ++begin) {
+    code_merge += begin->rawcode() << ((4 * i) - 1);
+  }
+
+  if (code_merge >= unicode::UniChar::kOutOfUnicode) {
+    THROW_EXCEPTION_(lexer::LexException,
+                     unicode::Convert(
+                         "out of valid unicode range : ").Append(string));
+  }
+
+  *code = unicode::UniChar(code_merge);
+}
diff --git a/src/lexer/charactor_lexer.h b/src/lexer/charactor_lexer.h
new file mode 100755 (executable)
index 0000000..5538ab2
--- /dev/null
@@ -0,0 +1,116 @@
+// Scheme構文における文字を判定するためのLexerです。
+// ここで定義されるLexerは、IPartsOfLexerから派生しており、以下の条件
+// をもってLexerDispatcherからディスパッチします。
+// :検索対象文字列の先頭 = #\ の場合:
+#ifndef _UTAKATA_SRC_LEXER_CHARACTOR_LEXER_H_
+#define _UTAKATA_SRC_LEXER_CHARACTOR_LEXER_H_
+
+#include "src/lexer/lexer_interface.h"
+
+namespace utakata {
+namespace unicode {
+class UniString;
+class UniChar;
+};
+
+namespace lexeme {
+class ILexeme;
+}
+
+namespace reader {
+class EncodingReader;
+}
+
+namespace lexer {
+class CharactorDispatchTerm {
+ public:
+  CharactorDispatchTerm() {}
+  virtual ~CharactorDispatchTerm() {}
+
+  // ディスパッチを行うかどうかを判定します。
+  virtual bool IsDispatch(const unicode::UniString& string) const;
+};
+
+struct CharactorNames {
+  // charactor name の固定値です。それぞれ固有の値ですので、
+  // 定数として定義しています。
+  static const std::string kNUL       = "nul";
+  static const std::string kALARM     = "alarm";
+  static const std::string kBACKSPACE = "backspace";
+  static const std::string kTAB       = "tab";
+  static const std::string kLINEFEED  = "linefeed";
+  static const std::string kNEWLINE   = "newline";
+  static const std::string kVTAB      = "vtab";
+  static const std::string kPAGE      = "page";
+  static const std::string kRETURN    = "return";
+  static const std::string kESC       = "esc";
+  static const std::string kSPACE     = "space";
+  static const std::string kDELETE    = "delete";
+
+  // 渡されたstringがCharctor Nameであるかどうかを判別します。
+  // ここで許可されるCharactor Nameは次の通りです。
+  // それぞれは右に記載されているUnicode文字に変換されます。
+  // nul       U+0000
+  // alarm     U+0007
+  // backspace U+0008
+  // tab       U+0009
+  // linefeed  U+000A
+  // newline   U+000A
+  // vtab      U+000B
+  // page      U+000C
+  // return    U+000D
+  // esc       U+001B
+  // space     U+0020
+  // delete    U+007F
+  static bool IsCharactorName(const unicode::UniString& string);
+
+  // 渡されたunicodeの内容と一致するunicodeを返します。
+  // CharactorNameに該当しない場合、0x11ffffが返されます。
+  // 0x11ffffは、unicode:UniChar::kOutOfUnicodeとして定義されています。
+  static unsigned int GetCodeFromCharactorName(
+      const unicode::UniString& string);
+};
+
+class CharactorLexer : public IPartsOfLexer {
+  // Scheme構文における文字のチェックを行います。
+  // Scheme構文における文字リテラルは、以下のような形式となります。
+  //   #\<any charactor>
+  //   #\<charactor name>
+  //   #\x<hex scalar value>
+  // ただし、<any charactor>はかならず一文字の文字であり、デリミタか
+  // 入力の終端が続かない場合、charactor nameかhex xcalar value
+  // に該当しなければなりません。
+ public:
+
+  CharactorLexer() {}
+  virtual ~CharactorLexer() {}
+
+  // 読出しストリームへのポインタを受け取って、結果として生成した
+  // ILexemeインターフェースの派生クラスを返します。
+  virtual lexeme::ILexeme* Lex(const unicode::UniString& string,
+                               reader::EncodingReader* reader);
+
+  // このIPartOfLexerへとDispatchする条件を記載したDispatchTermを作成して
+  // 返します。返されたポインタは、取得側で削除する必要があります。
+  // 返された値の保持については、utility::scoped_ptrの利用を推奨します。
+  virtual ILexerDispatchTerm* GetTerm() const;
+
+ private:
+
+  // 与えられた文字列がCharactor Nameのいずれかと一致する場合、
+  // 変換後のUnicode文字を返します。
+  // IsCharactorNameがfalseとなるstringである場合、LexException例外
+  // が発生します。
+  void ConvertCharctorNameToCode(const unicode::UniString& string,
+                                 unicode::UniChar* code);
+
+  // 与えられたHex ValueをUnicode文字として解釈します。
+  // 与えられたHexValueが範囲外か、もしくはHexValueとして不正である場合、
+  // LexException例外が発生します。
+  void ConvertHexValueToCode(const unicode::UniString& string,
+                             unicode::UniChar* code);
+};
+}
+}
+
+#endif /* _UTAKATA_SRC_LEXER_CHARACTOR_LEXER_H_ */
diff --git a/src/lexer/delimiters.cpp b/src/lexer/delimiters.cpp
new file mode 100755 (executable)
index 0000000..9bedc1c
--- /dev/null
@@ -0,0 +1,110 @@
+#include "src/lexer/delimiters.h"
+#include "src/unicode.h"
+
+namespace delimiter = utakata::lexer_delimiter;
+namespace unicode = utakata::unicode;
+
+// 宣言のコメントを参照してください。
+bool delimiter::StarndardDelimiterChecker::operator()(
+    const unicode::UniChar& ch) {
+  switch (ch.rawcode()) {
+    case '(':
+    case '[':
+    case ')':
+    case ']':
+    case '"':
+    case ';':
+    case '#':
+      return true;
+    default:
+      return delimiter::WhitespaceChecker()(ch);
+  }
+}
+
+// 宣言のコメントを参照してください。
+bool delimiter::WhitespaceChecker::operator()(const unicode::UniChar& ch) {
+  switch (ch.rawcode()) {
+    case '\r':                  // carriage return
+    case '\n':                  // linefeed
+    case ' ':                   // space
+    case '\t':                  // tab
+    case '\v':                  // vertical tab
+    case '\f':                  // page
+      return true;
+    default:
+      return false;
+  }
+}
+
+// targetが\rである場合、次の一文字のチェックも必要となりますが、
+// \r単体である場合でも、改行として見做されます。
+bool delimiter::LineEndingChecker::operator()(const unicode::UniChar& target,
+                                              reader::EncodingReader* stream) {
+  switch (ch.rawcode()) {
+    case '\n':
+      return true;
+    case '\r': {
+      unicode::UniChar target_second(stream->Peek());
+      if (target_second.rawcode() == '\n') {
+        strm->Read();
+      }
+      return true;
+    }
+    default:
+      return false;
+  }
+}
+
+// 宣言のコメントを参照してください。
+bool delimiter::HexValueChecker::operator()(const unicode::UniChar& ch) {
+  if ((ch.rawcode() >= 'a' && ch.rawcode() <= 'f') ||
+      (ch.rawcode() >= 'A' && ch.rawcode() <= 'F') ||
+      (ch.rawcode() >= '0' && ch.rawcode() <= '9')) {
+    return true;
+  }
+  return false;
+}
+
+// 宣言のコメントを参照してください。
+bool delimiter::StringDelimiterChecker::operator()(const unicode::UniChar& ch) {
+  return ch.rawcode() == '"';
+}
+
+// prefixは2文字未満である場合は正常なプレフィックスでは無いとして処理を行いません。
+bool delimiter::NumberPrefixChecker::operator()(const unicode::UniString& str) {
+  if (str.size() < 2) {
+    return false;
+  }
+
+  const unicode::UniChar& first_sharp = str.At(0);
+  const unicode::UniChar& radix_type = str.At(0);
+  if (first_sharp.rawcode() == '#') {
+    if (radix_type.rawcode() == 'b' || radix_type.rawcode() == 'B' ||
+        radix_type.rawcode() == 'o' || radix_type.rawcode() == 'O' ||
+        radix_type.rawcode() == 'x' || radix_type.rawcode() == 'X' ||
+        radix_type.rawcode() == 'd' || radix_type.rawcode() == 'D') {
+      return true;
+    }
+  }
+  return false;
+}
+
+// exactnessは2文字であるため、渡された文字列のサイズが2未満である場合には
+// exactnessとみなしません。
+bool delimiter::NumberExactnessChecker::operator()(
+    const unicode::UniString& str) {
+  if (str.size() < 2) {
+    return false;
+  }
+
+  unicode::UniChar first_sharp = str.At(0);
+  unicode::UniChar exact_type = str.At(1);
+
+  if (first_sharp.rawcode() == '#') {
+    if (exact_type.rawcode() == 'i' || exact_type.rawcode() == 'I' ||
+        exact_type.rawcode() == 'e' || exact_type.rawcode() == 'E') {
+      return true;
+    }
+  }
+  return false;
+}
similarity index 50%
rename from src/delimiter.h
rename to src/lexer/delimiters.h
index c78c788..ed5008a 100755 (executable)
 // 付与されます。
 // また、一文字の判定のみで問題無い場合にはUniCharを、複数文字の
 // 判定が必要である場合、UniStringを渡します。
-#ifndef _DELIMITER_H_
-#define _DELIMITER_H_
-
-#include "src/unicode.h"
-#include "src/common/smart_ptr.h"
+#ifndef _UTAKATA_SRC_LEXER_DELIMITERS_H_
+#define _UTAKATA_SRC_LEXER_DELIMITERS_H_
 
 namespace utakata {
 
@@ -25,58 +22,80 @@ class UniChar;
 };
 
 namespace reader {
-class StreamReader;
+class EncodingReader;
 };
 
 namespace lexer_delimiter {
 
-//==============================================================================
-// 各デリミタを判別するための関数オブジェクト。
-//==============================================================================
-
-class Normal {
+class StarndardDelimiterChecker {
   // 通常のデリミタとして処理するべきで文字であるか調査します。
  public:
-  bool operator()(const utakata::unicode::UniChar& ch);
+  StarndardDelimiterChecker() {}
+  // 渡された文字が以下の文字である場合、デリミタと判定されます。
+  // ( ) [ ] " . ; # に加え、WhitespaceCheckerがtrueを返す文字
+  bool operator()(const unicode::UniChar& ch);
 };
 
-class Whitespace {
+class WhitespaceChecker {
   // 空白として認識される文字であるかどうか調査します。
  public:
-  bool operator()(const utakata::unicode::UniChar& ch);
+  WhitespaceChecker() {}
+  // 空白として認識されるデータである場合、trueを返します。
+  // 空白として認識される文字は以下になります。
+  // --------------------
+  // carriage return 復帰
+  // linefeed  改行
+  // space 空白
+  // tab タブ
+  // vertical tab 垂直タブ
+  // page 改ページ
+  // --------------------
+  bool operator()(const unicode::UniChar& ch);
 };
 
-class LineEnding {
+class LineEndingChecker {
   // 改行と認識される文字であるかどうかを調査します。但し、改行は複数の
   // 文字である場合があるため、chの次の位置の文字列も必要となります。
  public:
-  bool operator()(const utakata::unicode::UniChar& ch,
-                  smart_ptr<reader::StreamReader> strm);
+  LineEndingChecker() {}
+  bool operator()(const unicode::UniChar& ch,
+                  reader::EncodingReader* reader);
 };
 
-class String {
+class StringDelimiterChecker {
   // 文字列を分割するためのデリミタであるかどうか調査します。
  public:
-  bool operator()(const utakata::unicode::UniChar& ch);
+  StringDelimiterChecker() {}
+
+  // デリミタは " のみです。
+  bool operator()(const unicode::UniChar& ch);
 };
 
-class Prefix {
+class NumberPrefixChecker {
   // <number>のプレフィックスであるかどうか調査します。
  public:
-  bool operator()(const utakata::unicode::UniString& str);
+
+  // プレフィックスは以下の形式です。
+  // #[ b | B | o | O | d | D | h | H ]
+  bool operator()(const unicode::UniString& str);
 };
 
-class Exactness {
+class NumberExactnessChecker {
   // <number>の正確性のデリミタであるかどうか調査します。
  public:
-  bool operator()(const utakata::unicode::UniString& str);
+
+  // exactnessのデリミタは以下の形式です。
+  // #[ i | I | e | E ]
+  bool operator()(const unicode::UniString& str);
 };
 
-class HexValue {
+class HexValueChecker {
   // 16進数で利用可能な文字の範囲であるかどうか調査します。
  public:
-  bool operator()(const utakata::unicode::UniChar& ch);
-};
-};
+  // 16進数で利用可能とされる文字の範囲であるかどうかを返します。
+  // [a-fA-F0-9] が該当し、大文字と小文字の区別は行いません。
+  bool operator()(const unicode::UniChar& ch);
 };
-#endif /* _DELIMITER_H_ */
+}
+}
+#endif /* _UTAKATA_SRC_LEXER_DELIMITERS_H_ */
similarity index 99%
rename from src/lexer_dispatcher.h
rename to src/lexer/lexer_dispatcher.h
index 9cfd6a7..69f9368 100755 (executable)
@@ -27,7 +27,7 @@ class UniChar;
 };
 
 namespace reader {
-class StreamReader;
+class EncodingReader;
 };
 
 namespace lexer {
similarity index 69%
rename from src/lexer_interface.h
rename to src/lexer/lexer_interface.h
index b35f54a..65606d9 100644 (file)
@@ -20,7 +20,7 @@ class UniString;
 }
 
 namespace reader {
-class StreamReader;
+class EncodingReader;
 };
 
 namespace lexeme {
@@ -30,14 +30,21 @@ class ILexeme;
 namespace lexer {
 
 class LexException : public exception::Exception {
+  // 字句解析時に発生した例外を送出します。
  public:
+
   LexException(const std::string& message,
-               const utakata::exception::ExceptionInfo& info) :
-      Exception(message, info) {}
+               const utakata::exception::ExceptionInfo& info)
+      Exception(message, info) {}
   LexException(const utakata::exception::Exception& exception,
                const std::string& message,
-               const utakata::exception::ExceptionInfo& info) :
-      Exception(exception, message, info) {}
+               const utakata::exception::ExceptionInfo& info)
+      : Exception(message, info) {}
+
+
+ private:
+  // LexExceptionが発生した▼文字列
+  const utility::smart_ptr<unicode::UniString> error_string_;
 };
 
 class ILexerDispatchTerm {
@@ -59,23 +66,23 @@ class IPartOfLexer {
 
   // 読出しストリームへのポインタを受け取って、結果として生成した
   // ILexemeインターフェースの派生クラスを返します。
-  virtual utility::smart_ptr<lexeme::ILexeme> Lex(
-      const unicode::UniString& string, reader::StreamReader* stream) = 0;
+  virtual lexeme::ILexeme* Lex(const unicode::UniString& string,
+                               reader::EncodingReader* stream) = 0;
+
+  // このIPartOfLexerへとDispatchする条件を記載したDispatchTermを作成して
+  // 返します。返されたポインタは、取得側で削除する必要があります。
+  // 返された値の保持については、utility::scoped_ptrの利用を推奨します。
+  virtual ILexerDispatchTerm* GetTerm() const = 0;
 };
 
 class ILexerCreator {
-  // IPartOfLexerの生成と、生成したLexerの条件を設定した
-  // LexerDispatchTerm生成するインターフェースとなります。
-  // LexerDispatchTermには、Lexerの条件を設定する必要があります。
+  // IPartOfLexerを生成するインターフェースとなります。
+  // 各IPartOfLexerにつき一つのインターフェースが必要となります。
  public:
   virtual ~ILexerCreator() {}
 
   // 各非終端記号に該当するIPartOfLexer派生のLexerを作成します。
   virtual IPartOfLexer* Create() const = 0;
-
-  // このILexerCreatorが生成するIPartOfLexerへとDispatchする条件を記載
-  // したDispatchTermを返します。
-  virtual ILexerDispatchTerm* GetTerm() const = 0;
 };
 };
 };
similarity index 100%
rename from src/number_lexer.h
rename to src/lexer/number_lexer.h
similarity index 67%
rename from src/scheme_lexer.h
rename to src/lexer/scheme_lexer.h
index 999c005..e961be0 100755 (executable)
@@ -1,7 +1,6 @@
-// Schemeの字句解析を行う。
 //
 // schemeの字句解析機であるSchemeLexerクラスを提供します。
-// SchemeLexerクラスは、StreamReaderクラスからスクリプトを読込
+// SchemeLexerクラスは、EncodingReaderクラスからScheme構文を読み出し
 // 各構文要素をILexeme派生クラスとして返します。
 //
 // example
@@ -13,8 +12,8 @@
 // while (!(p = lex.lex(reader))->Equal(lexeme::EOF)) {
 //   ...
 // }
-#ifndef _LEXER_H_
-#define _LEXER_H_
+#ifndef _UTAKATA_SRC_LEXER_SCHEME_LEXER_H_
+#define _UTAKATA_SRC_LEXER_SCHEME_LEXER_H_
 
 #include "src/common/smart_ptr.h"
 
@@ -30,22 +29,22 @@ class StreamReader;
 
 namespace lexer {
 
-class Lexer {
+class SchemeLexer {
   // scheme構文の字句解析器です。
   // ストリームから文字列を読みだし、schemeの字句構文に基づき、
   // 対応するILexeme形式のデータに変換されます。
   // SchemeLexerの実際の処理は、sublexer.hに定義されている
   // 内部Lexerによって定義されています。
  public:
-  Lexer() {}
-  virtual ~Lexer() {}
+  SchemeLexer() {}
+  virtual ~SchemeLexer() {}
 
-  // 渡されたStreamReaderから、字句構文を解析します。
-  // StreamReaderの末尾に到達した場合、lexeme::EOFが返されます。
+  // 渡されたEncodingReaderから、字句構文を解析します。
+  // EncodingReaderの末尾に到達した場合、lexeme::EOFが返されます。
   smart_ptr<utakata::lexeme::ILexeme> lex(
-      utakata::reader::StreamReader& stream);
+      reader::EncodingReader* reader);
 };
 };                                      // end of namespace `lexer`
 };                                      // end of namespace `lexer`
 
-#endif /* _LEXER_H_ */
+#endif /* _UTAKATA_SRC_LEXER_SCHEME_LEXER_H_ */
diff --git a/src/lexer/string_lexer.cpp b/src/lexer/string_lexer.cpp
new file mode 100755 (executable)
index 0000000..70153f2
--- /dev/null
@@ -0,0 +1,62 @@
+#include "src/exception_macro.h"
+#include "src/lexer/string_lexer.h"
+#include "src/lexer/delimiters.h"
+#include "src/lexeme.h"
+
+namespace lexer = utakata::lexer;
+namespace delimiter = utakata::lexer_delimiter;
+
+// 宣言のコメントを参照してください。
+bool lexer::StringDispatchTerm::IsDispatch(
+    const unicode::UniString& string) const {
+  if (!ch.IsEmpty() && ch.At(0).rawcode() == '"') {
+    return true;
+  }
+
+  return false;
+}
+
+// 文字列の終了地点は、同一行の`"`か、\\を含む複数行後の対応する`"`となります。
+// 対応する`"`が存在しないままreaderの末尾に到達すると、LexExceptionが
+// 送出されます。
+// また、行末から次の行の最初の文字までが、改行か空白のみである場合、
+// 行末から次の空白以外の文字までの文字列は無視され、文字列は継続している
+// とみなされます。
+lexeme::ILexeme* lexer::StringLexer::Lex(const unicode::UniString& string.
+                                         reader::EncodingReader* reader) {
+  if (reader == NULL) {
+    THROW_EXCEPTION_(lexer::LexException, "reader must valid instance");
+  }
+
+  delimiter::StarndardDelimiterChecker std_delimiter();
+  delimiter::StringDelimiterChecker string_delimiter();
+  delimiter::WhitespaceChecker white_delimiter();
+  delimiter::LineEndingChecker lineending_checker();
+
+  unicode::UniString str();
+  bool syntax_ok = false;
+
+  while (!reader->IsEof() && !syntax_ok) {
+    UniChar tmp(stream->Peek());
+
+    if (string_delimiter(tmp)) {
+      stream->Read();
+      syntax_ok = true;
+      break;
+    }
+
+    if (lineending_checker(tmp, reader)) {
+      while (!stream->IsEof() && (white_delimiter(tmp) || std_delimiter(tmp))) {
+        stream->Read();
+      }
+    } else {
+      str.Append(unicode::UniChar(stream->read()));
+    }
+  }
+
+  if (!syntax_ok) {
+    THROW_EXCEPTION_(lexer::LexException, "not found end of string.");
+  }
+
+  return new lexeme::StringLexeme(str);
+}
diff --git a/src/lexer/string_lexer.h b/src/lexer/string_lexer.h
new file mode 100755 (executable)
index 0000000..df377db
--- /dev/null
@@ -0,0 +1,57 @@
+// Scheme構文における文字列を判定する内部Lexerを提供します。
+// ここで定義されるLexerは、IPartsOfLexerから派生しており、以下の条件
+// をもってLexerDispatcherからディスパッチします。
+// :検索対象文字列の先頭 = " の場合:
+#ifndef _UTAKATA_SRC_LEXER_STRING_LEXER_H_
+#define _UTAKATA_SRC_LEXER_STRING_LEXER_H_
+
+#include "src/lexer/lexer_interface.h"
+
+namespace utakata {
+namespace unicode {
+class UniString;
+class UniChar;
+};
+
+namespace lexeme {
+class ILexeme;
+}
+
+namespace reader {
+class EncodingReader;
+}
+
+namespace lexer {
+class StringDispatchTerm {
+ public:
+  StringDispatchTerm() {}
+  virtual ~StringDispatchTerm() {}
+
+  // ディスパッチを行うかどうかを判定します。
+  virtual bool IsDispatch(const unicode::UniString& string) const;
+};
+
+class StringLexer : public IPartsOfLexer {
+  // 検索対象文字列の先頭が`"`である場合に、次の`"`に到達する
+  // までを文字列として抽出するLexerです。
+  // Lexが開始された後、次の`"`に到達する前に、readerの終端に到達
+  // した場合、LexExceptionが送出されます。
+ public:
+
+  StringLexer() {}
+  virtual ~StringLexer() {}
+
+  // 読出しストリームへのポインタを受け取って、結果として生成した
+  // ILexemeインターフェースの派生クラスを返します。
+  virtual lexeme::ILexeme* Lex(const unicode::UniString& string,
+                               reader::EncodingReader* reader);
+
+  // このIPartOfLexerへとDispatchする条件を記載したDispatchTermを作成して
+  // 返します。返されたポインタは、取得側で削除する必要があります。
+  // 返された値の保持については、utility::scoped_ptrの利用を推奨します。
+  virtual ILexerDispatchTerm* GetTerm() const;
+};
+}
+}
+
+#endif /* _UTAKATA_SRC_LEXER_STRING_LEXER_H_ */
index 6e118af..796aba5 100644 (file)
@@ -8,37 +8,46 @@
 #include <string>
 #include <vector>
 #include "src/exception.h"
+#include "src/unicode,h"
 
 namespace utakata {
 
+namespace unicode {
+class UniString;
+}
+
 namespace reader {
 
 class EndOfDeviceException : public exception::Exception {
   // reader::IReaderインターフェースの派生クラスにおいて、
   // 末尾に到達しているにも関わらず読み出しが行われた場合に送出されます。
  public:
-  EndOfDeviceException(const std::string& message,
+  EndOfDeviceException(const unicode::UniString message,
                        const utakata::exception::ExceptionInfo& info) :
       Exception(message, info) {}
 
   EndOfDeviceException(const utakata::exception::Exception& exception,
-                       const std::string& message,
+                       const unicode::UniString message,
                        const utakata::exception::ExceptionInfo& info) :
       Exception(exception, message, info) {}
+
+  virtual const char* what() const throw() {return "EndOfDeviceException";}
 };
 
 class IOException : public exception::Exception {
   // reader::IReaderインターフェースの派生クラスにおいて、
   // 入出力に対して発生する例外です。
  public:
-  IOException(const std::string& message,
+  IOException(const unicode::UniString message,
               const utakata::exception::ExceptionInfo& info) :
       Exception(message, info) {}
 
   IOException(const utakata::exception::Exception& exception,
-              const std::string& message,
+              const unicode::UniString message,
               const utakata::exception::ExceptionInfo& info) :
       Exception(exception, message, info) {}
+
+  virtual const char* what() const throw() {return "IOException";}
 };
 
 // IReader::Seekの方向を制御します。
index 294b2d9..d563e48 100755 (executable)
@@ -72,8 +72,6 @@ size_t reader::StringReader::GetPos() const {
 // seekposにゼロ以下の値が渡された場合、失敗と判定されます。
 bool reader::StringReader::Seek(
     int seekpos, reader::SeekDirection direction) {
-  CheckInternal();
-
   if (seekpos <= 0) {
     return false;
   }
index 2f84de8..2f34bcb 100644 (file)
@@ -32,7 +32,8 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 bin_PROGRAMS = string_reader_test$(EXEEXT) file_reader_test$(EXEEXT) \
        utf8_transcoder_test$(EXEEXT) unicode_test$(EXEEXT) \
-       encoding_reader_test$(EXEEXT)
+       encoding_reader_test$(EXEEXT) type_test$(EXEEXT) \
+       textarrayformat_test$(EXEEXT)
 subdir = src/test
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -58,6 +59,14 @@ am_string_reader_test_OBJECTS = string_reader_test.$(OBJEXT) \
        string_reader.$(OBJEXT) gtest-all.$(OBJEXT)
 string_reader_test_OBJECTS = $(am_string_reader_test_OBJECTS)
 string_reader_test_LDADD = $(LDADD)
+am_textarrayformat_test_OBJECTS = textarrayformat.$(OBJEXT) \
+       textarrayformat_test.$(OBJEXT) gtest-all.$(OBJEXT)
+textarrayformat_test_OBJECTS = $(am_textarrayformat_test_OBJECTS)
+textarrayformat_test_LDADD = $(LDADD)
+am_type_test_OBJECTS = type.$(OBJEXT) type_test.$(OBJEXT) \
+       gtest-all.$(OBJEXT)
+type_test_OBJECTS = $(am_type_test_OBJECTS)
+type_test_LDADD = $(LDADD)
 am_unicode_test_OBJECTS = unicode_test.$(OBJEXT) unicode.$(OBJEXT) \
        utf8_transcoder.$(OBJEXT) string_reader.$(OBJEXT) \
        gtest-all.$(OBJEXT)
@@ -77,19 +86,21 @@ CXXLD = $(CXX)
 CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
        -o $@
 SOURCES = $(encoding_reader_test_SOURCES) $(file_reader_test_SOURCES) \
-       $(string_reader_test_SOURCES) $(unicode_test_SOURCES) \
+       $(string_reader_test_SOURCES) $(textarrayformat_test_SOURCES) \
+       $(type_test_SOURCES) $(unicode_test_SOURCES) \
        $(utf8_transcoder_test_SOURCES)
 DIST_SOURCES = $(encoding_reader_test_SOURCES) \
        $(file_reader_test_SOURCES) $(string_reader_test_SOURCES) \
+       $(textarrayformat_test_SOURCES) $(type_test_SOURCES) \
        $(unicode_test_SOURCES) $(utf8_transcoder_test_SOURCES)
 ETAGS = etags
 CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-ACLOCAL = ${SHELL} /home/derui/develop/utakata/missing --run aclocal-1.10
-AMTAR = ${SHELL} /home/derui/develop/utakata/missing --run tar
-AUTOCONF = ${SHELL} /home/derui/develop/utakata/missing --run autoconf
-AUTOHEADER = ${SHELL} /home/derui/develop/utakata/missing --run autoheader
-AUTOMAKE = ${SHELL} /home/derui/develop/utakata/missing --run automake-1.10
+ACLOCAL = ${SHELL} /cygdrive/c/meadow/develop/utakata/missing --run aclocal-1.10
+AMTAR = ${SHELL} /cygdrive/c/meadow/develop/utakata/missing --run tar
+AUTOCONF = ${SHELL} /cygdrive/c/meadow/develop/utakata/missing --run autoconf
+AUTOHEADER = ${SHELL} /cygdrive/c/meadow/develop/utakata/missing --run autoheader
+AUTOMAKE = ${SHELL} /cygdrive/c/meadow/develop/utakata/missing --run automake-1.10
 AWK = gawk
 CC = gcc
 CCDEPMODE = depmode=gcc3
@@ -99,16 +110,16 @@ CPPFLAGS =
 CXX = g++
 CXXDEPMODE = depmode=gcc3
 CXXFLAGS = -g -O2
-CYGPATH_W = echo
+CYGPATH_W = cygpath -w
 DEFS = -DHAVE_CONFIG_H
 DEPDIR = .deps
 ECHO_C = 
 ECHO_N = -n
 ECHO_T = 
 EGREP = /bin/grep -E
-EXEEXT = 
+EXEEXT = .exe
 GREP = /bin/grep
-INSTALL = /usr/bin/install -c
+INSTALL = /bin/install -c
 INSTALL_DATA = ${INSTALL} -m 644
 INSTALL_PROGRAM = ${INSTALL}
 INSTALL_SCRIPT = ${INSTALL}
@@ -117,7 +128,7 @@ LDFLAGS =
 LIBOBJS = 
 LIBS = 
 LTLIBOBJS = 
-MAKEINFO = ${SHELL} /home/derui/develop/utakata/missing --run makeinfo
+MAKEINFO = ${SHELL} /cygdrive/c/meadow/develop/utakata/missing --run makeinfo
 MKDIR_P = /bin/mkdir -p
 OBJEXT = o
 PACKAGE = utakata
@@ -125,16 +136,17 @@ PACKAGE_BUGREPORT = BUG-REPORT-ADDRESS
 PACKAGE_NAME = utakata
 PACKAGE_STRING = utakata 0.0.1
 PACKAGE_TARNAME = utakata
+PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = 0.0.1
 PATH_SEPARATOR = :
 SET_MAKE = 
 SHELL = /bin/sh
 STRIP = 
 VERSION = 0.0.1
-abs_builddir = /home/derui/develop/utakata/src/test
-abs_srcdir = /home/derui/develop/utakata/src/test
-abs_top_builddir = /home/derui/develop/utakata
-abs_top_srcdir = /home/derui/develop/utakata
+abs_builddir = /cygdrive/c/meadow/develop/utakata/src/test
+abs_srcdir = /cygdrive/c/meadow/develop/utakata/src/test
+abs_top_builddir = /cygdrive/c/meadow/develop/utakata
+abs_top_srcdir = /cygdrive/c/meadow/develop/utakata
 ac_ct_CC = gcc
 ac_ct_CXX = g++
 am__include = include
@@ -154,7 +166,7 @@ host_alias =
 htmldir = ${docdir}
 includedir = ${prefix}/include
 infodir = ${datarootdir}/info
-install_sh = $(SHELL) /home/derui/develop/utakata/install-sh
+install_sh = $(SHELL) /cygdrive/c/meadow/develop/utakata/install-sh
 libdir = ${exec_prefix}/lib
 libexecdir = ${exec_prefix}/libexec
 localedir = ${datarootdir}/locale
@@ -189,6 +201,8 @@ unicode_test_SOURCES = unicode_test.cpp ../unicode.cpp ../utf8_transcoder.cpp  .
 encoding_reader_test_SOURCES = ../encoding_reader.cpp ../string_reader.cpp ../utf8_transcoder.cpp \
        encoding_reader_test.cpp  gtest/gtest-all.cc
 
+type_test_SOURCES = ../type.cpp type_test.cpp gtest/gtest-all.cc
+textarrayformat_test_SOURCES = ../common/textarrayformat.cpp  textarrayformat_test.cpp gtest/gtest-all.cc
 all: all-am
 
 .SUFFIXES:
@@ -254,6 +268,12 @@ file_reader_test$(EXEEXT): $(file_reader_test_OBJECTS) $(file_reader_test_DEPEND
 string_reader_test$(EXEEXT): $(string_reader_test_OBJECTS) $(string_reader_test_DEPENDENCIES) 
        @rm -f string_reader_test$(EXEEXT)
        $(CXXLINK) $(string_reader_test_OBJECTS) $(string_reader_test_LDADD) $(LIBS)
+textarrayformat_test$(EXEEXT): $(textarrayformat_test_OBJECTS) $(textarrayformat_test_DEPENDENCIES) 
+       @rm -f textarrayformat_test$(EXEEXT)
+       $(CXXLINK) $(textarrayformat_test_OBJECTS) $(textarrayformat_test_LDADD) $(LIBS)
+type_test$(EXEEXT): $(type_test_OBJECTS) $(type_test_DEPENDENCIES) 
+       @rm -f type_test$(EXEEXT)
+       $(CXXLINK) $(type_test_OBJECTS) $(type_test_LDADD) $(LIBS)
 unicode_test$(EXEEXT): $(unicode_test_OBJECTS) $(unicode_test_DEPENDENCIES) 
        @rm -f unicode_test$(EXEEXT)
        $(CXXLINK) $(unicode_test_OBJECTS) $(unicode_test_LDADD) $(LIBS)
@@ -274,6 +294,10 @@ include ./$(DEPDIR)/file_reader_test.Po
 include ./$(DEPDIR)/gtest-all.Po
 include ./$(DEPDIR)/string_reader.Po
 include ./$(DEPDIR)/string_reader_test.Po
+include ./$(DEPDIR)/textarrayformat.Po
+include ./$(DEPDIR)/textarrayformat_test.Po
+include ./$(DEPDIR)/type.Po
+include ./$(DEPDIR)/type_test.Po
 include ./$(DEPDIR)/unicode.Po
 include ./$(DEPDIR)/unicode_test.Po
 include ./$(DEPDIR)/utf8_transcoder.Po
@@ -363,6 +387,34 @@ file_reader.obj: ../file_reader.cpp
 #      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
 #      $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o file_reader.obj `if test -f '../file_reader.cpp'; then $(CYGPATH_W) '../file_reader.cpp'; else $(CYGPATH_W) '$(srcdir)/../file_reader.cpp'; fi`
 
+textarrayformat.o: ../common/textarrayformat.cpp
+       $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT textarrayformat.o -MD -MP -MF $(DEPDIR)/textarrayformat.Tpo -c -o textarrayformat.o `test -f '../common/textarrayformat.cpp' || echo '$(srcdir)/'`../common/textarrayformat.cpp
+       mv -f $(DEPDIR)/textarrayformat.Tpo $(DEPDIR)/textarrayformat.Po
+#      source='../common/textarrayformat.cpp' object='textarrayformat.o' libtool=no \
+#      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
+#      $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o textarrayformat.o `test -f '../common/textarrayformat.cpp' || echo '$(srcdir)/'`../common/textarrayformat.cpp
+
+textarrayformat.obj: ../common/textarrayformat.cpp
+       $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT textarrayformat.obj -MD -MP -MF $(DEPDIR)/textarrayformat.Tpo -c -o textarrayformat.obj `if test -f '../common/textarrayformat.cpp'; then $(CYGPATH_W) '../common/textarrayformat.cpp'; else $(CYGPATH_W) '$(srcdir)/../common/textarrayformat.cpp'; fi`
+       mv -f $(DEPDIR)/textarrayformat.Tpo $(DEPDIR)/textarrayformat.Po
+#      source='../common/textarrayformat.cpp' object='textarrayformat.obj' libtool=no \
+#      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
+#      $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o textarrayformat.obj `if test -f '../common/textarrayformat.cpp'; then $(CYGPATH_W) '../common/textarrayformat.cpp'; else $(CYGPATH_W) '$(srcdir)/../common/textarrayformat.cpp'; fi`
+
+type.o: ../type.cpp
+       $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT type.o -MD -MP -MF $(DEPDIR)/type.Tpo -c -o type.o `test -f '../type.cpp' || echo '$(srcdir)/'`../type.cpp
+       mv -f $(DEPDIR)/type.Tpo $(DEPDIR)/type.Po
+#      source='../type.cpp' object='type.o' libtool=no \
+#      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
+#      $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o type.o `test -f '../type.cpp' || echo '$(srcdir)/'`../type.cpp
+
+type.obj: ../type.cpp
+       $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT type.obj -MD -MP -MF $(DEPDIR)/type.Tpo -c -o type.obj `if test -f '../type.cpp'; then $(CYGPATH_W) '../type.cpp'; else $(CYGPATH_W) '$(srcdir)/../type.cpp'; fi`
+       mv -f $(DEPDIR)/type.Tpo $(DEPDIR)/type.Po
+#      source='../type.cpp' object='type.obj' libtool=no \
+#      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \
+#      $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o type.obj `if test -f '../type.cpp'; then $(CYGPATH_W) '../type.cpp'; else $(CYGPATH_W) '$(srcdir)/../type.cpp'; fi`
+
 unicode.o: ../unicode.cpp
        $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT unicode.o -MD -MP -MF $(DEPDIR)/unicode.Tpo -c -o unicode.o `test -f '../unicode.cpp' || echo '$(srcdir)/'`../unicode.cpp
        mv -f $(DEPDIR)/unicode.Tpo $(DEPDIR)/unicode.Po
index 60e39ba..30d8ba4 100755 (executable)
@@ -6,7 +6,7 @@ LC_ALL=C
 # SIBDIRS = . 
 
 bin_PROGRAMS = string_reader_test file_reader_test utf8_transcoder_test unicode_test \
-       encoding_reader_test
+       encoding_reader_test type_test textarrayformat_test
 
 check_PROGRANS = $(bin_PROGRAMS)
 TESTS = $(bin_PROGRAMS)
@@ -16,4 +16,6 @@ file_reader_test_SOURCES = file_reader_test.cpp ../file_reader.cpp gtest/gtest-a
 utf8_transcoder_test_SOURCES = ../utf8_transcoder.cpp utf8_transcoder_test.cpp  ../string_reader.cpp gtest/gtest-all.cc
 unicode_test_SOURCES = unicode_test.cpp ../unicode.cpp ../utf8_transcoder.cpp  ../string_reader.cpp gtest/gtest-all.cc
 encoding_reader_test_SOURCES = ../encoding_reader.cpp ../string_reader.cpp ../utf8_transcoder.cpp \
-       encoding_reader_test.cpp  gtest/gtest-all.cc
\ No newline at end of file
+       encoding_reader_test.cpp  gtest/gtest-all.cc
+type_test_SOURCES =  ../type.cpp type_test.cpp gtest/gtest-all.cc
+textarrayformat_test_SOURCES = ../common/textarrayformat.cpp  textarrayformat_test.cpp gtest/gtest-all.cc
index bfcdc0f..6dc51a9 100644 (file)
@@ -32,7 +32,8 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 bin_PROGRAMS = string_reader_test$(EXEEXT) file_reader_test$(EXEEXT) \
        utf8_transcoder_test$(EXEEXT) unicode_test$(EXEEXT) \
-       encoding_reader_test$(EXEEXT)
+       encoding_reader_test$(EXEEXT) type_test$(EXEEXT) \
+       textarrayformat_test$(EXEEXT)
 subdir = src/test
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -58,6 +59,14 @@ am_string_reader_test_OBJECTS = string_reader_test.$(OBJEXT) \
        string_reader.$(OBJEXT) gtest-all.$(OBJEXT)
 string_reader_test_OBJECTS = $(am_string_reader_test_OBJECTS)
 string_reader_test_LDADD = $(LDADD)
+am_textarrayformat_test_OBJECTS = textarrayformat.$(OBJEXT) \
+       textarrayformat_test.$(OBJEXT) gtest-all.$(OBJEXT)
+textarrayformat_test_OBJECTS = $(am_textarrayformat_test_OBJECTS)
+textarrayformat_test_LDADD = $(LDADD)
+am_type_test_OBJECTS = type.$(OBJEXT) type_test.$(OBJEXT) \
+       gtest-all.$(OBJEXT)
+type_test_OBJECTS = $(am_type_test_OBJECTS)
+type_test_LDADD = $(LDADD)
 am_unicode_test_OBJECTS = unicode_test.$(OBJEXT) unicode.$(OBJEXT) \
        utf8_transcoder.$(OBJEXT) string_reader.$(OBJEXT) \
        gtest-all.$(OBJEXT)
@@ -77,10 +86,12 @@ CXXLD = $(CXX)
 CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
        -o $@
 SOURCES = $(encoding_reader_test_SOURCES) $(file_reader_test_SOURCES) \
-       $(string_reader_test_SOURCES) $(unicode_test_SOURCES) \
+       $(string_reader_test_SOURCES) $(textarrayformat_test_SOURCES) \
+       $(type_test_SOURCES) $(unicode_test_SOURCES) \
        $(utf8_transcoder_test_SOURCES)
 DIST_SOURCES = $(encoding_reader_test_SOURCES) \
        $(file_reader_test_SOURCES) $(string_reader_test_SOURCES) \
+       $(textarrayformat_test_SOURCES) $(type_test_SOURCES) \
        $(unicode_test_SOURCES) $(utf8_transcoder_test_SOURCES)
 ETAGS = etags
 CTAGS = ctags
@@ -125,6 +136,7 @@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
 PACKAGE_NAME = @PACKAGE_NAME@
 PACKAGE_STRING = @PACKAGE_STRING@
 PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
 SET_MAKE = @SET_MAKE@
@@ -189,6 +201,8 @@ unicode_test_SOURCES = unicode_test.cpp ../unicode.cpp ../utf8_transcoder.cpp  .
 encoding_reader_test_SOURCES = ../encoding_reader.cpp ../string_reader.cpp ../utf8_transcoder.cpp \
        encoding_reader_test.cpp  gtest/gtest-all.cc
 
+type_test_SOURCES = ../type.cpp type_test.cpp gtest/gtest-all.cc
+textarrayformat_test_SOURCES = ../common/textarrayformat.cpp  textarrayformat_test.cpp gtest/gtest-all.cc
 all: all-am
 
 .SUFFIXES:
@@ -254,6 +268,12 @@ file_reader_test$(EXEEXT): $(file_reader_test_OBJECTS) $(file_reader_test_DEPEND
 string_reader_test$(EXEEXT): $(string_reader_test_OBJECTS) $(string_reader_test_DEPENDENCIES) 
        @rm -f string_reader_test$(EXEEXT)
        $(CXXLINK) $(string_reader_test_OBJECTS) $(string_reader_test_LDADD) $(LIBS)
+textarrayformat_test$(EXEEXT): $(textarrayformat_test_OBJECTS) $(textarrayformat_test_DEPENDENCIES) 
+       @rm -f textarrayformat_test$(EXEEXT)
+       $(CXXLINK) $(textarrayformat_test_OBJECTS) $(textarrayformat_test_LDADD) $(LIBS)
+type_test$(EXEEXT): $(type_test_OBJECTS) $(type_test_DEPENDENCIES) 
+       @rm -f type_test$(EXEEXT)
+       $(CXXLINK) $(type_test_OBJECTS) $(type_test_LDADD) $(LIBS)
 unicode_test$(EXEEXT): $(unicode_test_OBJECTS) $(unicode_test_DEPENDENCIES) 
        @rm -f unicode_test$(EXEEXT)
        $(CXXLINK) $(unicode_test_OBJECTS) $(unicode_test_LDADD) $(LIBS)
@@ -274,6 +294,10 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gtest-all.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string_reader.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string_reader_test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/textarrayformat.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/textarrayformat_test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/type.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/type_test.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unicode.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unicode_test.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utf8_transcoder.Po@am__quote@
@@ -363,6 +387,34 @@ file_reader.obj: ../file_reader.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o file_reader.obj `if test -f '../file_reader.cpp'; then $(CYGPATH_W) '../file_reader.cpp'; else $(CYGPATH_W) '$(srcdir)/../file_reader.cpp'; fi`
 
+textarrayformat.o: ../common/textarrayformat.cpp
+@am__fastdepCXX_TRUE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT textarrayformat.o -MD -MP -MF $(DEPDIR)/textarrayformat.Tpo -c -o textarrayformat.o `test -f '../common/textarrayformat.cpp' || echo '$(srcdir)/'`../common/textarrayformat.cpp
+@am__fastdepCXX_TRUE@  mv -f $(DEPDIR)/textarrayformat.Tpo $(DEPDIR)/textarrayformat.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='../common/textarrayformat.cpp' object='textarrayformat.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o textarrayformat.o `test -f '../common/textarrayformat.cpp' || echo '$(srcdir)/'`../common/textarrayformat.cpp
+
+textarrayformat.obj: ../common/textarrayformat.cpp
+@am__fastdepCXX_TRUE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT textarrayformat.obj -MD -MP -MF $(DEPDIR)/textarrayformat.Tpo -c -o textarrayformat.obj `if test -f '../common/textarrayformat.cpp'; then $(CYGPATH_W) '../common/textarrayformat.cpp'; else $(CYGPATH_W) '$(srcdir)/../common/textarrayformat.cpp'; fi`
+@am__fastdepCXX_TRUE@  mv -f $(DEPDIR)/textarrayformat.Tpo $(DEPDIR)/textarrayformat.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='../common/textarrayformat.cpp' object='textarrayformat.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o textarrayformat.obj `if test -f '../common/textarrayformat.cpp'; then $(CYGPATH_W) '../common/textarrayformat.cpp'; else $(CYGPATH_W) '$(srcdir)/../common/textarrayformat.cpp'; fi`
+
+type.o: ../type.cpp
+@am__fastdepCXX_TRUE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT type.o -MD -MP -MF $(DEPDIR)/type.Tpo -c -o type.o `test -f '../type.cpp' || echo '$(srcdir)/'`../type.cpp
+@am__fastdepCXX_TRUE@  mv -f $(DEPDIR)/type.Tpo $(DEPDIR)/type.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='../type.cpp' object='type.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o type.o `test -f '../type.cpp' || echo '$(srcdir)/'`../type.cpp
+
+type.obj: ../type.cpp
+@am__fastdepCXX_TRUE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT type.obj -MD -MP -MF $(DEPDIR)/type.Tpo -c -o type.obj `if test -f '../type.cpp'; then $(CYGPATH_W) '../type.cpp'; else $(CYGPATH_W) '$(srcdir)/../type.cpp'; fi`
+@am__fastdepCXX_TRUE@  mv -f $(DEPDIR)/type.Tpo $(DEPDIR)/type.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     source='../type.cpp' object='type.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o type.obj `if test -f '../type.cpp'; then $(CYGPATH_W) '../type.cpp'; else $(CYGPATH_W) '$(srcdir)/../type.cpp'; fi`
+
 unicode.o: ../unicode.cpp
 @am__fastdepCXX_TRUE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT unicode.o -MD -MP -MF $(DEPDIR)/unicode.Tpo -c -o unicode.o `test -f '../unicode.cpp' || echo '$(srcdir)/'`../unicode.cpp
 @am__fastdepCXX_TRUE@  mv -f $(DEPDIR)/unicode.Tpo $(DEPDIR)/unicode.Po
index be41c31..22151a9 100755 (executable)
@@ -1,3 +1,4 @@
+#include <iostream>
 #include <algorithm>
 #include <gtest/gtest.h>
 
@@ -8,7 +9,7 @@
 namespace reader = utakata::reader;
 namespace transcoder = utakata::transcoder;
 
-TEST(UTF8TranscoderTest, EncodingTest) {
+TEST(EncodingReaderTest, EncodingTest) {
   reader::StringReader sr("UTF8");
 
   reader::EncodingReader reader(&sr, new transcoder::UTF8Transcoder);
@@ -32,7 +33,7 @@ TEST(UTF8TranscoderTest, EncodingTest) {
   EXPECT_TRUE(reader.IsEof());
 }
 
-TEST(UTF8TranscoderTest, MultiByteTest) {
+TEST(EncodingReaderTest, MultiByteTest) {
   reader::StringReader sr("あいuうえお");
   reader::EncodingReader reader(&sr, new transcoder::UTF8Transcoder);
   unsigned int checker = reader.Read();
index f3544fd..b176919 100755 (executable)
@@ -89,8 +89,7 @@ TEST_F(FileReaderTest, OpenAndClose) {
   EXPECT_THROW(reader.Read(), reader::EndOfDeviceException);
 }
 
-int main(int argc, char** argv)
-{
+int main(int argc, char** argv) {
   testing::InitGoogleTest(&argc, argv);
 
   return RUN_ALL_TESTS();
index 4a8af3e..58470b6 100644 (file)
@@ -1,36 +1,40 @@
-#include <string>
-#include <iostream>
-#include <sstream>
-
-#include "../simpletest.h"
-#include "../textarrayformat.h"
-#include "../smart_function_callback.h"
-
-using namespace std;
-
-bool taf_test(smart_ptr<simpletest::SimpleTestAsserter> asserter)
-{
-    std::stringstream ss;
-
-    ss << "=====" << std::endl;
-    ss << "test" << std::endl << "test" << std::endl;
-    ss << "=====" << endl;
-    ss << "testhoge" << endl;
-    ss << "=====" << endl;
-    ss << "test\ntest" << endl;
-    
-    textarrayformat::TextArrayReader reader(ss);
-    asserter->check(reader.get(), "test\ntest\n");
-    asserter->check(reader.get(1), "testhoge\n");
-    asserter->check(reader.get(0), "test\ntest\n");
-    asserter->check(reader.get(2), "test\ntest\n");
-
-    return asserter->isOk();
+#include <gtest/gtest.h>
+#include <vector>
+#include <stdexcept>
+#include "src/common/textarrayformat.h"
+
+namespace textarrayformat = utility::textarrayformat;
+
+TEST(TextArrayFormatTest, GenAndReadTest) {
+  textarrayformat::TextArrayGenerator gen("======");
+
+  gen.Append("test");
+  gen.Append("test");
+  EXPECT_EQ(gen.construct_text(), "======\n");
+
+  gen.Append(gen.separator());
+  EXPECT_EQ(gen.separator() + "test\ntest\n" + gen.separator(),
+            gen.construct_text());
+
+  std::string prev = gen.construct_text();
+  gen.Append("testhoge");
+  gen.Punctuate();
+
+  EXPECT_EQ(prev + "testhoge\n" + gen.separator(),
+            gen.construct_text());
+
+  textarrayformat::TextArrayReader reader(gen);
+  EXPECT_EQ(reader.GetBlockAt(0), "test\ntest\n");
+  EXPECT_EQ(reader.GetBlockAt(1), "testhoge\n");
+  EXPECT_THROW(reader.GetBlockAt(2), std::out_of_range);
+  EXPECT_THROW(reader.GetBlockAt(-1), std::out_of_range);
+
+  std::vector<std::string> s = reader.text_blocks();
+  EXPECT_EQ(s.size(), static_cast<unsigned int>(2));
 }
 
-int main(int argc, char *argv[])
-{
-    simpletest::SimpleTestSuite suite("textarrayformat");
-    suite.addTester(sfcr::screate(taf_test, suite.getAsserter()));
-    return suite.run();
+int main(int argc, char** argv) {
+  testing::InitGoogleTest(&argc, argv);
+
+  return RUN_ALL_TESTS();
 }
index 4af7ccf..f990490 100755 (executable)
@@ -2,88 +2,37 @@
 #include <sstream>
 #include <string>
 #include <functional>
+#include <gtest/gtest.h>
 
-#include "../simpletest.h"
+#include "src/type.h"
 
-#include "../type.h"
-#include "base_object.h"
-#include "../data_structure_interface.h"
-#include "../data_castor.h"
+namespace type = utakata::type;
 
-using namespace std;
-using namespace utakata;
+TEST(TypeTest, TypeHashTest) {
+  type::Type t1("string test");
+  type::Type t2("string test");
 
-class Stub : public data::DataEntity
-{
-public:
-    Stub(std::string test) : test_(test) {}
-    virtual ~Stub() {}
+  // 同一となるはず。
+  EXPECT_TRUE(t1 == t2);
+  EXPECT_FALSE(t1 != t2);
 
-    virtual void* getAddress() {return static_cast<void*>(&test_);}
-    virtual const void* getAddress() const {return static_cast<const void*>(&test_);}
-    smart_ptr<unicode::UniString> toString() {return smart_ptr<unicode::UniString>();}
+  type::Type t3("string test1");
+  EXPECT_TRUE(t3 != t2);
+  EXPECT_FALSE(t3 == t2);
 
-private:
+  EXPECT_EQ(t1.hash(), t2.hash());
 
-    std::string test_;
-};
+  type::Type t4("number test");
 
-bool typehash_test(smart_ptr<simpletest::SimpleTestAsserter> asserter)
-{
-    // schemeのオブジェクト中で利用されるデータ及び型に対するフロントエンド
-    // のテスト。
-
-    type::Type t1("string test");
-    type::Type t2("string test");
-
-    // 同一となるはず。
-    asserter->check(t1 == t2, true);
-    asserter->check(t1 != t2, false);
-
-    type::Type t3("string test1");
-    asserter->check(t3 != t2, true);
-    asserter->check(t3 == t2, false);
-
-    // ハッシュのベースとなっている文字列は、テンプレート指定しているため、
-    // 同一オブジェクトなら必ず一致する。
-    asserter->check(t1.getHash(), t2.getHash(), "boolean ");
-
-    type::Type t4("number test");
-    // ベース文字列が違えば完全に異なる。
-    asserter->check(t3 != t4, true);
-    asserter->check(t3 == t4, false);
-    asserter->check(t4 != t2, true);
-    asserter->check(t4 == t2, false);
-    
-    return asserter->isOk();
+  EXPECT_TRUE(t3 != t4);
+  EXPECT_FALSE(t3 == t4);
+  EXPECT_TRUE(t4 != t2);
+  EXPECT_FALSE(t4 == t2);
 }
 
-bool typedescripter_test(smart_ptr<simpletest::SimpleTestAsserter> asserter)
-{
-
-    // 型に対する情報が設定されたデータに対するテスト。
+int main(int argc, char** argv) {
+  testing::InitGoogleTest(&argc, argv);
 
-    std::string t = "test string";
-    smart_ptr<data::DataEntity> s(new Stub(std::string(t)));
-    type::Type h("string");
-
-    type::TypeDescripter des(h, s);
-
-    // 型情報にはTypeへの直接アクセスが可能。
-    asserter->check(h.getHash(), des.getType().getHash());
-
-    // データへの直接アクセスを可能とする。
-    smart_ptr<data::DataEntity> s2 = des.getEntity();
-
-    return asserter->isOk();
+  return RUN_ALL_TESTS();
 }
 
-int main(int argc, char *argv[])
-{
-    simpletest::SimpleTestSuite suite("environment test");
-    suite.addTester(sfcr::screate(typehash_test, suite.getAsserter()));
-    suite.addTester(sfcr::screate(typedescripter_test, suite.getAsserter()));
-    suite.run();
-    return 0;
-}
index 8d6057f..a90aca2 100755 (executable)
@@ -1,3 +1,4 @@
+#include <iostream>
 #include <algorithm>
 #include <gtest/gtest.h>
 
index c4925ca..7942fa0 100755 (executable)
@@ -29,6 +29,8 @@ class EncodeException : public exception::Exception {
                   const std::string& message,
                   const utakata::exception::ExceptionInfo& info) :
       Exception(exception, message, info) {}
+
+  virtual const char* what() const throw() {return "EncodeException";}
 };
 
 class DecodeException : public exception::Exception {
@@ -44,6 +46,8 @@ class DecodeException : public exception::Exception {
                   const std::string& message,
                   const utakata::exception::ExceptionInfo& info) :
       Exception(exception, message, info) {}
+
+  virtual const char* what() const throw() {reutrn "DecodeException";}
 };
 
 class ITranscoder {
index 51e5aea..c00de14 100755 (executable)
@@ -5,11 +5,6 @@
 namespace type = utakata::type;
 
 // 宣言のコメントを参照してください。
-type::Type::Type(const std::string& str) : hash_(0), hash_string_(str) {
-  MakeHash();
-}
-
-// 宣言のコメントを参照してください。
 type::Type::Type(const type::Type& t) : hash_(t.hash_),
                                         hash_string_(t.hash_string_) {}
 
index b572438..73ce67e 100755 (executable)
@@ -39,12 +39,12 @@ class Type {
 };
 
 // Typeのhashが等しい場合、trueを返します。
-bool operator==(const Type& lh, const Type& rh) {
+inline bool operator==(const Type& lh, const Type& rh) {
   return lh.hash() == rh.hash();
 }
 
 // Typeのhashが異なる場合、trueを返します。
-bool operator!=(const Type& lh, const Type& rh) {
+inline bool operator!=(const Type& lh, const Type& rh) {
   return !(lh.hash() == rh.hash());
 }
 };
index 2287534..8ebc2df 100755 (executable)
@@ -24,6 +24,10 @@ class UniChar {
   // 実装されており、各operator overloadを利用しないことも可能です。
  public:
 
+  // Schemeシステム内で最大値となるUnicode値です。この値以上の
+  // Unicodeは無効です。
+  static const unsigned int kOutOfUnicode = 0x11FFFF;
+
   UniChar() : rawcode_(0x0000) {}
   virtual ~UniChar() {}