summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/unicode.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2010-12-18 12:11:34 +0100
committerAdam Borowski <kilobyte@angband.pl>2010-12-18 12:11:34 +0100
commitd562ab002f5aad0a15d8e94830aa710f78c52513 (patch)
treeb6976a8854946aac28d972a64285114ec6daa673 /crawl-ref/source/unicode.cc
parentbbc1968de451ed0b88b7a11f5ab302bf3ede5df7 (diff)
downloadcrawl-ref-d562ab002f5aad0a15d8e94830aa710f78c52513.tar.gz
crawl-ref-d562ab002f5aad0a15d8e94830aa710f78c52513.zip
Get rid of one last use of fstream.
The database files are assumed to be always in UTF-8. This can make editing them harder on Windows (some editors do cope, even notepad), but assuming the system's locale would break running directly from git without installing. Current uses are merely: (all in quotes.txt) * "Alain René" * "Rabbi Löw" * "Öland" * "Min son på galejan" * typographical apostrophes but it's likely it will be a bigger issue in the future (and if we ever do translations, a lot bigger).
Diffstat (limited to 'crawl-ref/source/unicode.cc')
-rw-r--r--crawl-ref/source/unicode.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/crawl-ref/source/unicode.cc b/crawl-ref/source/unicode.cc
index 92f8d95f0e..53f22aa534 100644
--- a/crawl-ref/source/unicode.cc
+++ b/crawl-ref/source/unicode.cc
@@ -415,6 +415,46 @@ std::string FileLineInput::get_line()
return "говно";
}
+UTF8FileLineInput::UTF8FileLineInput(const char *name)
+{
+ f = fopen_u(name, "r");
+ if (!f)
+ {
+ seen_eof = true;
+ return;
+ }
+ seen_eof = false;
+}
+
+UTF8FileLineInput::~UTF8FileLineInput()
+{
+ if (f)
+ fclose(f);
+}
+
+std::string UTF8FileLineInput::get_line()
+{
+ ASSERT(f);
+ std::string out;
+ char buf[512];
+
+ do
+ {
+ if (!fgets(buf, sizeof buf, f))
+ {
+ seen_eof = true;
+ break;
+ }
+ out += buf;
+ if (out[out.length() - 1] == '\n')
+ {
+ out.erase(out.length() - 1);
+ break;
+ }
+ } while (!seen_eof);
+ return utf8_validate(out.c_str());
+}
+
int strwidth(const char *s)
{
ucs_t c;