aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt3
-rw-r--r--src/common/Logger.cpp21
-rw-r--r--src/common/String.cpp56
-rw-r--r--src/osx/graphics/quartz/CMakeLists.txt2
-rw-r--r--src/parse/Grammar.cpp20
-rw-r--r--src/platform/Color.cpp1
6 files changed, 81 insertions, 22 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 1056a763..e1642da2 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -30,5 +30,4 @@ else()
endif()
find_package(Microsoft.GSL CONFIG REQUIRED)
-find_package(fmt CONFIG REQUIRED)
-target_link_libraries(cru_base PUBLIC Microsoft.GSL::GSL fmt::fmt)
+target_link_libraries(cru_base PUBLIC Microsoft.GSL::GSL)
diff --git a/src/common/Logger.cpp b/src/common/Logger.cpp
index af1dd692..e77e8a85 100644
--- a/src/common/Logger.cpp
+++ b/src/common/Logger.cpp
@@ -30,7 +30,7 @@ void Logger::RemoveSource(ILogSource *source) {
}
namespace {
-std::u16string_view LogLevelToString(LogLevel level) {
+String LogLevelToString(LogLevel level) {
switch (level) {
case LogLevel::Debug:
return u"DEBUG";
@@ -45,36 +45,35 @@ std::u16string_view LogLevelToString(LogLevel level) {
}
}
-std::u16string GetLogTime() {
+String GetLogTime() {
auto time = std::time(nullptr);
auto calendar = std::localtime(&time);
- return fmt::format(u"{}:{}:{}", calendar->tm_hour, calendar->tm_min,
- calendar->tm_sec);
+ return Format(u"{}:{}:{}", calendar->tm_hour, calendar->tm_min,
+ calendar->tm_sec);
}
} // namespace
-void Logger::Log(LogLevel level, std::u16string_view s) {
+void Logger::Log(LogLevel level, const String &message) {
#ifndef CRU_DEBUG
if (level == LogLevel::Debug) {
return;
}
#endif
for (const auto &source : sources_) {
- source->Write(level, fmt::format(u"[{}] {}: {}\n", GetLogTime(),
- LogLevelToString(level), s));
+ source->Write(level, Format(u"[{}] {}: {}\n", GetLogTime(),
+ LogLevelToString(level), message));
}
}
-void Logger::Log(LogLevel level, std::u16string_view tag,
- std::u16string_view s) {
+void Logger::Log(LogLevel level, const String &tag, const String &message) {
#ifndef CRU_DEBUG
if (level == LogLevel::Debug) {
return;
}
#endif
for (const auto &source : sources_) {
- source->Write(level, fmt::format(u"[{}] {} {}: {}\n", GetLogTime(),
- LogLevelToString(level), tag, s));
+ source->Write(level, Format(u"[{}] {} {}: {}\n", GetLogTime(),
+ LogLevelToString(level), tag, message));
}
}
} // namespace cru::log
diff --git a/src/common/String.cpp b/src/common/String.cpp
index e9acf984..94eb8f27 100644
--- a/src/common/String.cpp
+++ b/src/common/String.cpp
@@ -101,6 +101,10 @@ String::~String() {
}
}
+String::String(from_buffer_tag, std::uint16_t* buffer, Index size,
+ Index capacity)
+ : buffer_(buffer), size_(size), capacity_(capacity) {}
+
void String::resize(Index new_size) {
Expects(new_size >= 0);
@@ -137,7 +141,7 @@ void String::reserve(Index new_capacity) {
}
}
-String::iterator String::insert(const_iterator pos, std::uint16_t* str,
+String::iterator String::insert(const_iterator pos, const std::uint16_t* str,
Index size) {
Index new_size = size_ + size;
if (new_size > capacity_) {
@@ -239,4 +243,54 @@ int String::Compare(const String& other) const {
}
}
+namespace details {
+std::vector<FormatToken> ParseToFormatTokenList(const String& str) {
+ std::vector<FormatToken> result;
+
+ auto push_char = [&result](std::uint16_t c) {
+ if (result.empty() || result.back().type == FormatTokenType::PlaceHolder) {
+ result.push_back(FormatToken{FormatTokenType::Text, String{}});
+ }
+ result.back().data.append(c);
+ };
+
+ bool last_is_left_bracket = false;
+ for (auto c : str) {
+ if (c == u'{') {
+ if (last_is_left_bracket) {
+ push_char(u'{');
+ last_is_left_bracket = false;
+ } else {
+ last_is_left_bracket = true;
+ }
+ } else if (c == u'}') {
+ if (last_is_left_bracket) {
+ result.push_back(FormatToken{FormatTokenType::PlaceHolder, String{}});
+ }
+ last_is_left_bracket = false;
+ } else {
+ if (last_is_left_bracket) {
+ push_char(u'{');
+ }
+ push_char(c);
+ last_is_left_bracket = false;
+ }
+ }
+ return result;
+}
+
+void FormatAppendFromFormatTokenList(
+ String& current, const std::vector<FormatToken>& format_token_list,
+ Index index) {
+ for (Index i = index; i < format_token_list.size(); i++) {
+ const auto& token = format_token_list[i];
+ if (token.type == FormatTokenType::PlaceHolder) {
+ current += u"{}";
+ } else {
+ current += token.data;
+ }
+ }
+}
+} // namespace details
+
} // namespace cru
diff --git a/src/osx/graphics/quartz/CMakeLists.txt b/src/osx/graphics/quartz/CMakeLists.txt
index c6bb29cb..868a3ee2 100644
--- a/src/osx/graphics/quartz/CMakeLists.txt
+++ b/src/osx/graphics/quartz/CMakeLists.txt
@@ -20,6 +20,6 @@ target_sources(cru_osx_graphics_quartz PUBLIC
${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Resource.hpp
${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/TextLayout.hpp
)
-target_link_libraries(cru_osx_graphics_quartz PUBLIC cocoa)
+target_link_libraries(cru_osx_graphics_quartz PUBLIC quartz)
target_link_libraries(cru_osx_graphics_quartz PUBLIC cru_osx_base cru_platform_graphics)
diff --git a/src/parse/Grammar.cpp b/src/parse/Grammar.cpp
index 95c65e99..34eb2dd4 100644
--- a/src/parse/Grammar.cpp
+++ b/src/parse/Grammar.cpp
@@ -122,8 +122,6 @@ Grammar::GenerateLeftProductionMap() const {
}
void Grammar::EliminateLeftRecursions() {
- // TODO: Use a better name.
-
auto nonterminals = nonterminals_;
for (int i = 0; i < nonterminals.size(); i++) {
auto ni = nonterminals[i];
@@ -148,6 +146,7 @@ void Grammar::EliminateLeftRecursions() {
auto new_right = right;
new_right.insert(new_right.cbegin(), jp->GetRight().cbegin(),
jp->GetRight().cend());
+ // TODO: What should this name be.
CreateProduction(u"", ni, std::move(new_right));
}
}
@@ -167,22 +166,29 @@ void Grammar::EliminateLeftRecursions() {
}
}
- auto ni_h = CreateNonterminal(u"");
+ auto ni_h = CreateNonterminal(ni->GetName() +
+ u" (Eliminate Left Recursion Helper)");
for (auto p : i_nr_ps) {
auto right = p->GetRight();
right.push_back(ni_h);
- CreateProduction(u"", ni, std::move(right));
+ CreateProduction(p->GetName() + u" (Eliminate Left Recursion Of " +
+ ni->GetName() + u")",
+ ni, std::move(right));
}
for (auto p : i_r_ps) {
auto right = p->GetRight();
right.erase(right.cbegin());
right.push_back(ni_h);
- CreateProduction(u"", ni_h, std::move(right));
+ CreateProduction(p->GetName() + u" (Eliminate Left Recursion Of " +
+ ni->GetName() + u")",
+ ni_h, std::move(right));
}
- CreateProduction(u"", ni_h, std::vector<Symbol*>{});
+ CreateProduction(u"Empty Production (Eliminate Left Recursion Of " +
+ ni->GetName() + u")",
+ ni_h, std::vector<Symbol*>{});
for (auto p : i_r_ps) {
RemoveProduction(p);
@@ -193,4 +199,6 @@ void Grammar::EliminateLeftRecursions() {
}
}
}
+
+void Grammar::LeftFactor() {}
} // namespace cru::parse
diff --git a/src/platform/Color.cpp b/src/platform/Color.cpp
index fe512715..c4cc511b 100644
--- a/src/platform/Color.cpp
+++ b/src/platform/Color.cpp
@@ -6,7 +6,6 @@
#include <stdexcept>
#include <string>
#include <string_view>
-#include "fmt/core.h"
namespace cru::platform {
std::string Color::ToUtf8String() const {