libept
|
00001 // -*- C++ -*- 00002 #ifndef EPT_CORE_APT_RECORDPARSER_H 00003 #define EPT_CORE_APT_RECORDPARSER_H 00004 00009 /* 00010 * Copyright (C) 2007 Enrico Zini <enrico@enricozini.org> 00011 * 00012 * This library is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Lesser General Public 00014 * License as published by the Free Software Foundation; either 00015 * version 2.1 of the License, or (at your option) any later version. 00016 * 00017 * This library is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 * Lesser General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 */ 00026 00027 #include <vector> 00028 #include <string> 00029 00030 namespace ept { 00031 namespace core { 00032 namespace record { 00033 00040 class RecordParser 00041 { 00043 std::string buffer; 00044 00046 std::vector<size_t> ends; 00047 00049 std::vector<size_t> sorted; 00050 00051 public: 00052 RecordParser() {} 00053 RecordParser(const std::string& str) { scan(str); } 00054 00056 void scan(const std::string& str); 00057 00063 size_t index(const std::string& str) const; 00064 00066 std::string field(size_t idx) const; 00067 00069 std::string name(size_t idx) const; 00070 00072 std::string lookup(size_t idx) const; 00073 00075 std::string lookup(const std::string& name) const { return lookup(index(name)); } 00076 00078 std::string operator[](size_t idx) const { return lookup(idx); } 00079 00081 std::string operator[](const std::string& name) const { return lookup(name); } 00082 00084 const std::string& record() const { return buffer; } 00085 00087 std::string record() { return buffer; } 00088 00090 size_t size() const { return ends.size(); } 00091 }; 00092 00093 } 00094 } 00095 } 00096 00097 // vim:set ts=4 sw=4: 00098 #endif