From 730e5dde39333cb2f63c72a7d7152bee5c4dbb05 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 8 Feb 2014 15:09:25 -0800 Subject: Implement AString --- src/io/cxxstdio.hpp | 6 +++--- src/io/line.cpp | 10 ++++++---- src/io/line.hpp | 14 ++++++++------ src/io/lock.cpp | 10 +++++----- src/io/lock.hpp | 6 +++--- src/io/read.cpp | 6 +++--- src/io/read.hpp | 2 +- src/io/read_test.cpp | 10 +++++----- src/io/write_test.cpp | 12 ++++++------ 9 files changed, 40 insertions(+), 36 deletions(-) (limited to 'src/io') diff --git a/src/io/cxxstdio.hpp b/src/io/cxxstdio.hpp index b4b4c79..753a1fc 100644 --- a/src/io/cxxstdio.hpp +++ b/src/io/cxxstdio.hpp @@ -238,15 +238,15 @@ namespace cxxstdio # define FPRINTF(file, fmt, ...) XPRINTF(/*no_cast*/(file), fmt, ## __VA_ARGS__) # define FSCANF(file, fmt, ...) XSCANF(no_cast(file), fmt, ## __VA_ARGS__) # define PRINTF(fmt, ...) FPRINTF(stdout, fmt, ## __VA_ARGS__) -# define SPRINTF(str, fmt, ...) XPRINTF(base_cast(str), fmt, ## __VA_ARGS__) +# define SPRINTF(str, fmt, ...) XPRINTF(base_cast(str), fmt, ## __VA_ARGS__) # define SNPRINTF(str, n, fmt, ...) XPRINTF(base_cast&>(str), fmt, ## __VA_ARGS__) # define SCANF(fmt, ...) FSCANF(stdin, fmt, ## __VA_ARGS__) # define SSCANF(str, fmt, ...) XSCANF(/*ZString or compatible*/str, fmt, ## __VA_ARGS__) # define STRPRINTF(fmt, ...) \ - (/*[&]() -> FString*/ \ + (/*[&]() -> AString*/ \ { \ - FString _out_impl; \ + AString _out_impl; \ SPRINTF(_out_impl, fmt, ## __VA_ARGS__); \ /*return*/ _out_impl; \ }/*()*/) diff --git a/src/io/line.cpp b/src/io/line.cpp index 83f439d..fb73f45 100644 --- a/src/io/line.cpp +++ b/src/io/line.cpp @@ -21,7 +21,7 @@ #include #include -#include "../strings/fstring.hpp" +#include "../strings/astring.hpp" #include "../strings/mstring.hpp" #include "../strings/zstring.hpp" @@ -32,7 +32,7 @@ namespace io { - FString Line::message_str(ZString cat, ZString msg) + AString Line::message_str(ZString cat, ZString msg) { MString out; if (column) @@ -43,7 +43,7 @@ namespace io filename, line, cat, msg); out += STRPRINTF("%s\n", text); out += STRPRINTF("%*c\n", column, '^'); - return FString(out); + return AString(out); } void Line::message(ZString cat, ZString msg) @@ -68,8 +68,10 @@ namespace io bool LineReader::read_line(Line& l) { - if (rf.getline(l.text)) + AString text; + if (rf.getline(text)) { + l.text = text; l.filename = filename; l.line = ++line; l.column = 0; // whole line diff --git a/src/io/line.hpp b/src/io/line.hpp index 00f0a11..bdff1bb 100644 --- a/src/io/line.hpp +++ b/src/io/line.hpp @@ -21,7 +21,8 @@ # include "../sanity.hpp" -# include "../strings/fstring.hpp" +# include "../strings/rstring.hpp" +# include "../strings/astring.hpp" # include "../strings/zstring.hpp" # include "fd.hpp" @@ -30,15 +31,16 @@ namespace io { + // TODO split this out struct Line { - FString text; + RString text; - FString filename; + RString filename; // 1-based uint16_t line, column; - FString message_str(ZString cat, ZString msg); + AString message_str(ZString cat, ZString msg); void message(ZString cat, ZString msg); void note(ZString msg) { message("note", msg); } void warning(ZString msg) { message("warning", msg); } @@ -60,7 +62,7 @@ namespace io class LineReader { protected: - FString filename; + RString filename; uint16_t line, column; ReadFile rf; public: @@ -77,7 +79,7 @@ namespace io class LineCharReader : private LineReader { - FString line_text; + RString line_text; public: explicit LineCharReader(ZString name); diff --git a/src/io/lock.cpp b/src/io/lock.cpp index c7cbda8..96c3649 100644 --- a/src/io/lock.cpp +++ b/src/io/lock.cpp @@ -46,7 +46,7 @@ namespace io int no = getpid(); // Get a filename that doesn't already exist - FString newfile; + AString newfile; do { newfile = STRPRINTF("%s_%d.tmp", filename, no++); @@ -59,7 +59,7 @@ namespace io return fd; } - WriteLock::WriteLock(FString fn, bool linebuffered) + WriteLock::WriteLock(RString fn, bool linebuffered) : WriteFile(get_lock_open(fn, &tmp_suffix), linebuffered), filename(fn) {} WriteLock::~WriteLock() @@ -72,16 +72,16 @@ namespace io } int n = backup_count; - FString old_filename = STRPRINTF("%s.%d", filename, n); + AString old_filename = STRPRINTF("%s.%d", filename, n); while (--n) { - FString newer_filename = STRPRINTF("%s.%d", filename, n); + AString newer_filename = STRPRINTF("%s.%d", filename, n); rename(newer_filename.c_str(), old_filename.c_str()); old_filename = std::move(newer_filename); } rename(filename.c_str(), old_filename.c_str()); - FString tmpfile = STRPRINTF("%s_%d.tmp", filename, tmp_suffix); + AString tmpfile = STRPRINTF("%s_%d.tmp", filename, tmp_suffix); rename(tmpfile.c_str(), filename.c_str()); } } // namespace io diff --git a/src/io/lock.hpp b/src/io/lock.hpp index a19acdb..b5052cf 100644 --- a/src/io/lock.hpp +++ b/src/io/lock.hpp @@ -21,17 +21,17 @@ # include "write.hpp" -# include "../strings/fstring.hpp" +# include "../strings/rstring.hpp" namespace io { class WriteLock : public WriteFile { - FString filename; + RString filename; int tmp_suffix; public: - WriteLock(FString filename, bool linebuffered=false); + WriteLock(RString filename, bool linebuffered=false); ~WriteLock(); bool close() = delete; }; diff --git a/src/io/read.cpp b/src/io/read.cpp index fe2c765..2ef35cc 100644 --- a/src/io/read.cpp +++ b/src/io/read.cpp @@ -21,7 +21,7 @@ #include #include -#include "../strings/fstring.hpp" +#include "../strings/astring.hpp" #include "../strings/mstring.hpp" #include "../strings/zstring.hpp" @@ -74,7 +74,7 @@ namespace io } return len; } - bool ReadFile::getline(FString& line) + bool ReadFile::getline(AString& line) { MString tmp; char c; @@ -111,7 +111,7 @@ namespace io } else if (!happy && anything) PRINTF("warning: file does not contain a trailing newline\n"); - line = FString(tmp); + line = AString(tmp); return anything; } diff --git a/src/io/read.hpp b/src/io/read.hpp index 4830fa4..2355e46 100644 --- a/src/io/read.hpp +++ b/src/io/read.hpp @@ -44,7 +44,7 @@ namespace io bool get(char&); size_t get(char *buf, size_t len); - bool getline(FString&); + bool getline(AString&); bool is_open(); }; diff --git a/src/io/read_test.cpp b/src/io/read_test.cpp index ebb20ca..5d287dd 100644 --- a/src/io/read_test.cpp +++ b/src/io/read_test.cpp @@ -23,7 +23,7 @@ io::FD string_pipe(ZString sz) TEST(io, read1) { io::ReadFile rf(string_pipe("Hello")); - FString hi; + AString hi; EXPECT_TRUE(rf.getline(hi)); EXPECT_EQ(hi, "Hello"); EXPECT_FALSE(rf.getline(hi)); @@ -31,7 +31,7 @@ TEST(io, read1) TEST(io, read2) { io::ReadFile rf(string_pipe("Hello\n")); - FString hi; + AString hi; EXPECT_TRUE(rf.getline(hi)); EXPECT_EQ(hi, "Hello"); EXPECT_FALSE(rf.getline(hi)); @@ -39,7 +39,7 @@ TEST(io, read2) TEST(io, read3) { io::ReadFile rf(string_pipe("Hello\r")); - FString hi; + AString hi; EXPECT_TRUE(rf.getline(hi)); EXPECT_EQ(hi, "Hello"); EXPECT_FALSE(rf.getline(hi)); @@ -47,7 +47,7 @@ TEST(io, read3) TEST(io, read4) { io::ReadFile rf(string_pipe("Hello\r\n")); - FString hi; + AString hi; EXPECT_TRUE(rf.getline(hi)); EXPECT_EQ(hi, "Hello"); EXPECT_FALSE(rf.getline(hi)); @@ -55,7 +55,7 @@ TEST(io, read4) TEST(io, read5) { io::ReadFile rf(string_pipe("Hello\n\r")); - FString hi; + AString hi; EXPECT_TRUE(rf.getline(hi)); EXPECT_EQ(hi, "Hello"); EXPECT_TRUE(rf.getline(hi)); diff --git a/src/io/write_test.cpp b/src/io/write_test.cpp index a9736b8..f703850 100644 --- a/src/io/write_test.cpp +++ b/src/io/write_test.cpp @@ -5,7 +5,7 @@ #include #include -#include "../strings/fstring.hpp" +#include "../strings/astring.hpp" #include "../strings/mstring.hpp" #include "../strings/xstring.hpp" @@ -35,7 +35,7 @@ public: { rfd.close(); } - FString slurp() + AString slurp() { MString tmp; char buf[4096]; @@ -52,7 +52,7 @@ public: break; tmp += XString(buf + 0, buf + rv, nullptr); } - return FString(tmp); + return AString(tmp); } }; @@ -73,10 +73,10 @@ TEST(io, write2) PipeWriter pw(true); io::WriteFile& wf = pw.wf; wf.really_put("Hello, ", 7); - EXPECT_EQ("", std::string(pw.slurp().c_str())); + EXPECT_EQ("", pw.slurp()); wf.put_line("World!"); wf.really_put("XXX", 3); - EXPECT_EQ("Hello, World!\n", std::string(pw.slurp().c_str())); + EXPECT_EQ("Hello, World!\n", pw.slurp()); EXPECT_TRUE(wf.close()); - EXPECT_EQ("XXX", std::string(pw.slurp().c_str())); + EXPECT_EQ("XXX", pw.slurp()); } -- cgit v1.2.3-60-g2f50