Skip to content

Commit 66723ed

Browse files
committed
string型コンストラクタの利用方法を修正
1 parent ea6e51e commit 66723ed

2 files changed

Lines changed: 2 additions & 28 deletions

File tree

src/lexer.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ namespace JsonParser {
6565
case '8':
6666
case '9':
6767
{
68-
std::string str(&ch);
68+
std::string str(1, ch);
6969
ch = ss.get();
7070
while (!ss.eof() && ch != '}' && ch != ',' && ch != ']') {
7171
str += ch;
7272
ch = ss.get();
7373
}
7474
str = str.substr(0, str.find_last_not_of(" \f\t\v\r\n") + 1);
7575
if (!std::regex_match(str, std::regex("-?(0|[1-9]\\d*)(\\.\\d+)?(e[-+](0|[1-9]\\d*)(\\.\\d+)?)?"))) {
76-
std::cout << str << std::endl;
7776
throw std::runtime_error("At LexicalAnalyzer(): \"str\" is not a number.");
7877
}
7978
chs.push_back(str);
@@ -83,15 +82,14 @@ namespace JsonParser {
8382
case 'f':
8483
case 'n':
8584
{
86-
std::string str(&ch);
85+
std::string str(1, ch);
8786
ch = ss.get();
8887
while (!ss.eof() && ch != '}' && ch != ',' && ch != ']') {
8988
str += ch;
9089
ch = ss.get();
9190
}
9291
str = str.substr(0, str.find_last_not_of(" \f\t\v\r\n") + 1);
9392
if (str != "true" && str != "false" && str != "null") {
94-
std::cout << str << std::endl;
9593
throw std::runtime_error("At LexicalAnalyzer(): \"str\" is neither true, false nor null.");
9694
}
9795
chs.push_back(str);

test/lexer_test.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,12 @@ TEST(JsonParserTest, LexicalHappyTest6) {
3939
ASSERT_EQ(JsonParser::Lexer(ss).size(), 17);
4040
}
4141

42-
TEST(JsonParserTest, LexicalHappyTest6_1) {
43-
std::stringstream ss;
44-
ss << R"({ "pi": 5.14 })";
45-
ASSERT_EQ(JsonParser::Lexer(ss).size(), 5);
46-
}
47-
48-
TEST(JsonParserTest, LexicalHappyTest6_2) {
49-
std::stringstream ss;
50-
ss << R"({ "pi": 35.14 })";
51-
ASSERT_EQ(JsonParser::Lexer(ss).size(), 5);
52-
}
53-
5442
TEST(JsonParserTest, LexicalHappyTest7) {
5543
std::stringstream ss;
5644
ss << R"({ "name": null, "active_flag": true, "delete_flag": false })";
5745
ASSERT_EQ(JsonParser::Lexer(ss).size(), 13);
5846
}
5947

60-
TEST(JsonParserTest, LexicalHappyTest7_1) {
61-
std::stringstream ss;
62-
ss << R"({ "active_flag": true, "delete_flag": false })";
63-
ASSERT_EQ(JsonParser::Lexer(ss).size(), 9);
64-
}
65-
66-
TEST(JsonParserTest, LexicalHappyTest7_2) {
67-
std::stringstream ss;
68-
ss << R"({ "delete_flag": false })";
69-
ASSERT_EQ(JsonParser::Lexer(ss).size(), 5);
70-
}
71-
7248
TEST(JsonParserTest, LexicalHappyTest8) {
7349
std::stringstream ss;
7450
ss << R"({ "user_info": { "user_id": "A1234567", "user_name": "Yamada Taro" } })";

0 commit comments

Comments
 (0)