From 5f41f7c48df215f160a9418dd39595c954370cf8 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 21 Nov 2017 12:59:47 +0400 Subject: [PATCH] Clean code up a bit --- apps/openmw/mwgui/journalbooks.cpp | 10 +++------- apps/openmw/mwgui/journalviewmodel.cpp | 3 +-- components/misc/stringops.hpp | 4 ++-- components/misc/utf8stream.hpp | 5 +++++ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwgui/journalbooks.cpp b/apps/openmw/mwgui/journalbooks.cpp index 3b1463b45..68b1d8403 100644 --- a/apps/openmw/mwgui/journalbooks.cpp +++ b/apps/openmw/mwgui/journalbooks.cpp @@ -239,16 +239,13 @@ BookTypesetter::Ptr JournalBooks::createLatinJournalIndex () { char ch = 'A' + i; char buffer [32]; - sprintf (buffer, "( %c )", ch); char buffer2 [32]; sprintf(buffer2, "%c", ch); - const char * c = buffer2; - Utf8Stream stream ((unsigned char*) c,(unsigned char*) c + strlen(c)); + Utf8Stream stream (buffer2); uint32_t first = stream.peek(); - // TODO: find a way to store a multibyte character in the InteractiveId (this is a intptr_t) const MWGui::TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours(); BookTypesetter::Style* style = typesetter->createHotStyle (body, textColours.journalTopic, textColours.journalTopicOver, @@ -274,13 +271,12 @@ BookTypesetter::Ptr JournalBooks::createCyrillicJournalIndex () for (int i = 0; i < 32; ++i) { char buffer [32]; - sprintf(buffer, "( %c%c )", 0xd0, 0x90 + i); // CYRILLIC CAPITAL A is a 0xd090 in UTF-8 char buffer2 [32]; sprintf(buffer2, "%c%c", 0xd0, 0x90 + i); - const char * c = buffer2; - Utf8Stream stream ((unsigned char*) c,(unsigned char*) c + strlen(c)); + + Utf8Stream stream (buffer2); uint32_t first = stream.peek(); const MWGui::TextColours& textColours = MWBase::Environment::get().getWindowManager()->getTextColours(); diff --git a/apps/openmw/mwgui/journalviewmodel.cpp b/apps/openmw/mwgui/journalviewmodel.cpp index 3f8992e31..d7b233ff3 100644 --- a/apps/openmw/mwgui/journalviewmodel.cpp +++ b/apps/openmw/mwgui/journalviewmodel.cpp @@ -313,8 +313,7 @@ struct JournalViewModelImpl : JournalViewModel for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i) { - const char * c = i->first.c_str(); - Utf8Stream stream ((unsigned char*) c,(unsigned char*) c + strlen(c)); + Utf8Stream stream (i->first.c_str()); uint32_t first = Misc::StringUtils::toUpper(stream.peek()); if (first != character) diff --git a/components/misc/stringops.hpp b/components/misc/stringops.hpp index 5ce5360d1..cec2a34a4 100644 --- a/components/misc/stringops.hpp +++ b/components/misc/stringops.hpp @@ -58,7 +58,7 @@ public: static uint32_t toUpper(uint32_t ch) { - // Russian alphabete + // Russian alphabet if (ch >= 0x0430 && ch < 0x0450) ch -= 0x20; @@ -66,7 +66,7 @@ public: if (ch == 0x0451) ch -= 0x50; - // Latin alphabete + // Latin alphabet if (ch >= 0x61 && ch < 0x80) ch -= 0x20; diff --git a/components/misc/utf8stream.hpp b/components/misc/utf8stream.hpp index 760015902..368374a64 100644 --- a/components/misc/utf8stream.hpp +++ b/components/misc/utf8stream.hpp @@ -18,6 +18,11 @@ public: { } + Utf8Stream (const char * str) : + cur ((unsigned char*) str), nxt ((unsigned char*) str), end ((unsigned char*) str + strlen(str)), val(Utf8Stream::sBadChar()) + { + } + Utf8Stream (std::pair range) : cur (range.first), nxt (range.first), end (range.second), val(Utf8Stream::sBadChar()) {