Skip to content

Commit

Permalink
feat: Merge branch 'main' into find-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ToruNiina committed Jan 5, 2025
2 parents 93428f2 + 0468b76 commit 0f6e08f
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 185 deletions.
2 changes: 1 addition & 1 deletion docs/themes/hugo-book
Submodule hugo-book updated 91 files
+2 −2 .github/workflows/main.yml
+4 −4 README.md
+17 −14 assets/_main.scss
+16 −10 assets/_markdown.scss
+1 −0 assets/_shortcodes.scss
+4 −0 assets/_utils.scss
+0 −35 exampleSite/content.en/docs/shortcodes/expand.md
+2 −2 exampleSite/content.en/docs/shortcodes/tabs.md
+1 −0 exampleSite/resources/_gen/assets/book.scss_b807c86e8030af4cdc30edccea379f5f.content
+1 −0 exampleSite/resources/_gen/assets/book.scss_b807c86e8030af4cdc30edccea379f5f.json
+0 −1 exampleSite/resources/_gen/assets/book.scss_e129fe35b8d0a70789c8a08429469073.content
+0 −1 exampleSite/resources/_gen/assets/book.scss_e129fe35b8d0a70789c8a08429469073.json
+14 −0 i18n/nl.yaml
+1 −1 layouts/partials/docs/brand.html
+2 −1 layouts/partials/docs/footer.html
+2 −2 layouts/partials/docs/html-head.html
+5 −12 layouts/partials/docs/post-meta.html
+2 −2 layouts/posts/list.html
+6 −4 layouts/posts/single.html
+10 −10 layouts/shortcodes/button.html
+1 −1 layouts/shortcodes/details.html
+0 −13 layouts/shortcodes/expand.html
+1 −1 layouts/shortcodes/hint.html
+3 −3 layouts/shortcodes/mermaid.html
+1 −1 layouts/shortcodes/tab.html
+1 −2 layouts/shortcodes/tabs.html
+1 −1 static/katex/auto-render.min.js
+ static/katex/fonts/KaTeX_AMS-Regular.ttf
+ static/katex/fonts/KaTeX_AMS-Regular.woff
+ static/katex/fonts/KaTeX_AMS-Regular.woff2
+ static/katex/fonts/KaTeX_Caligraphic-Bold.ttf
+ static/katex/fonts/KaTeX_Caligraphic-Bold.woff
+ static/katex/fonts/KaTeX_Caligraphic-Bold.woff2
+ static/katex/fonts/KaTeX_Caligraphic-Regular.ttf
+ static/katex/fonts/KaTeX_Caligraphic-Regular.woff
+ static/katex/fonts/KaTeX_Caligraphic-Regular.woff2
+ static/katex/fonts/KaTeX_Fraktur-Bold.ttf
+ static/katex/fonts/KaTeX_Fraktur-Bold.woff
+ static/katex/fonts/KaTeX_Fraktur-Bold.woff2
+ static/katex/fonts/KaTeX_Fraktur-Regular.ttf
+ static/katex/fonts/KaTeX_Fraktur-Regular.woff
+ static/katex/fonts/KaTeX_Fraktur-Regular.woff2
+ static/katex/fonts/KaTeX_Main-Bold.ttf
+ static/katex/fonts/KaTeX_Main-Bold.woff
+ static/katex/fonts/KaTeX_Main-Bold.woff2
+ static/katex/fonts/KaTeX_Main-BoldItalic.ttf
+ static/katex/fonts/KaTeX_Main-BoldItalic.woff
+ static/katex/fonts/KaTeX_Main-BoldItalic.woff2
+ static/katex/fonts/KaTeX_Main-Italic.ttf
+ static/katex/fonts/KaTeX_Main-Italic.woff
+ static/katex/fonts/KaTeX_Main-Italic.woff2
+ static/katex/fonts/KaTeX_Main-Regular.ttf
+ static/katex/fonts/KaTeX_Main-Regular.woff
+ static/katex/fonts/KaTeX_Main-Regular.woff2
+ static/katex/fonts/KaTeX_Math-BoldItalic.ttf
+ static/katex/fonts/KaTeX_Math-BoldItalic.woff
+ static/katex/fonts/KaTeX_Math-BoldItalic.woff2
+ static/katex/fonts/KaTeX_Math-Italic.ttf
+ static/katex/fonts/KaTeX_Math-Italic.woff
+ static/katex/fonts/KaTeX_Math-Italic.woff2
+ static/katex/fonts/KaTeX_SansSerif-Bold.ttf
+ static/katex/fonts/KaTeX_SansSerif-Bold.woff
+ static/katex/fonts/KaTeX_SansSerif-Bold.woff2
+ static/katex/fonts/KaTeX_SansSerif-Italic.ttf
+ static/katex/fonts/KaTeX_SansSerif-Italic.woff
+ static/katex/fonts/KaTeX_SansSerif-Italic.woff2
+ static/katex/fonts/KaTeX_SansSerif-Regular.ttf
+ static/katex/fonts/KaTeX_SansSerif-Regular.woff
+ static/katex/fonts/KaTeX_SansSerif-Regular.woff2
+ static/katex/fonts/KaTeX_Script-Regular.ttf
+ static/katex/fonts/KaTeX_Script-Regular.woff
+ static/katex/fonts/KaTeX_Script-Regular.woff2
+ static/katex/fonts/KaTeX_Size1-Regular.ttf
+ static/katex/fonts/KaTeX_Size1-Regular.woff
+ static/katex/fonts/KaTeX_Size1-Regular.woff2
+ static/katex/fonts/KaTeX_Size2-Regular.ttf
+ static/katex/fonts/KaTeX_Size2-Regular.woff
+ static/katex/fonts/KaTeX_Size2-Regular.woff2
+ static/katex/fonts/KaTeX_Size3-Regular.ttf
+ static/katex/fonts/KaTeX_Size3-Regular.woff
+ static/katex/fonts/KaTeX_Size3-Regular.woff2
+ static/katex/fonts/KaTeX_Size4-Regular.ttf
+ static/katex/fonts/KaTeX_Size4-Regular.woff
+ static/katex/fonts/KaTeX_Size4-Regular.woff2
+ static/katex/fonts/KaTeX_Typewriter-Regular.ttf
+ static/katex/fonts/KaTeX_Typewriter-Regular.woff
+ static/katex/fonts/KaTeX_Typewriter-Regular.woff2
+1 −1 static/katex/katex.min.css
+1 −1 static/katex/katex.min.js
+1,147 −720 static/mermaid.min.js
+1 −1 theme.toml
42 changes: 36 additions & 6 deletions include/toml11/compat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,19 @@ using source_location = std::source_location;

inline std::string to_string(const source_location& loc)
{
return std::string(" at line ") + std::to_string(loc.line()) +
std::string(" in file ") + std::string(loc.file_name());
const char* fname = loc.file_name();
if(fname)
{
return std::string(" at line ") + std::to_string(loc.line()) +
std::string(" in file ") + std::string(fname);
}
else
{
return std::string(" at line ") + std::to_string(loc.line()) +
std::string(" in unknown file");
}
}

} // cxx
} // toml
#elif defined(TOML11_HAS_EXPERIMENTAL_SOURCE_LOCATION)
Expand All @@ -449,9 +459,19 @@ using source_location = std::experimental::source_location;

inline std::string to_string(const source_location& loc)
{
return std::string(" at line ") + std::to_string(loc.line()) +
std::string(" in file ") + std::string(loc.file_name());
const char* fname = loc.file_name();
if(fname)
{
return std::string(" at line ") + std::to_string(loc.line()) +
std::string(" in file ") + std::string(fname);
}
else
{
return std::string(" at line ") + std::to_string(loc.line()) +
std::string(" in unknown file");
}
}

} // cxx
} // toml
#elif defined(TOML11_HAS_BUILTIN_FILE_LINE)
Expand Down Expand Up @@ -483,9 +503,19 @@ struct source_location

inline std::string to_string(const source_location& loc)
{
return std::string(" at line ") + std::to_string(loc.line()) +
std::string(" in file ") + std::string(loc.file_name());
const char* fname = loc.file_name();
if(fname)
{
return std::string(" at line ") + std::to_string(loc.line()) +
std::string(" in file ") + std::string(fname);
}
else
{
return std::string(" at line ") + std::to_string(loc.line()) +
std::string(" in unknown file");
}
}

} // cxx
} // toml
#else // no builtin
Expand Down
16 changes: 10 additions & 6 deletions include/toml11/fwd/location_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class location

location(source_ptr src, std::string src_name)
: source_(std::move(src)), source_name_(std::move(src_name)),
location_(0), line_number_(1)
location_(0), line_number_(1), column_number_(1)
{}

location(const location&) = default;
Expand All @@ -41,7 +41,7 @@ class location
~location() = default;

void advance(std::size_t n = 1) noexcept;
void retrace(std::size_t n = 1) noexcept;
void retrace() noexcept;

bool is_ok() const noexcept { return static_cast<bool>(this->source_); }

Expand All @@ -54,22 +54,25 @@ class location
{
return this->location_;
}
void set_location(const std::size_t loc) noexcept;

std::size_t line_number() const noexcept
{
return this->line_number_;
}
std::size_t column_number() const noexcept
{
return this->column_number_;
}
std::string get_line() const;
std::size_t column_number() const noexcept;

source_ptr const& source() const noexcept {return this->source_;}
std::string const& source_name() const noexcept {return this->source_name_;}

private:

void advance_line_number(const std::size_t n);
void retrace_line_number(const std::size_t n);
void advance_impl(const std::size_t n);
void retrace_impl();
std::size_t calc_column_number() const noexcept;

private:

Expand All @@ -81,6 +84,7 @@ class location
std::string source_name_;
std::size_t location_; // std::vector<>::difference_type is signed
std::size_t line_number_;
std::size_t column_number_;
};

bool operator==(const location& lhs, const location& rhs) noexcept;
Expand Down
7 changes: 6 additions & 1 deletion include/toml11/fwd/region_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ class region
const_iterator cend() const noexcept;

std::string as_string() const;
std::vector<std::string> as_lines() const;
std::vector<std::pair<std::string, std::size_t>> as_lines() const;

source_ptr const& source() const noexcept {return this->source_;}
std::string const& source_name() const noexcept {return this->source_name_;}

private:

std::pair<std::string, std::size_t>
take_line(const_iterator begin, const_iterator end) const;

private:

source_ptr source_;
Expand Down
37 changes: 35 additions & 2 deletions include/toml11/fwd/source_location_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,34 @@
namespace toml
{

//
// A struct to contain location in a toml file.
//
// To reduce memory consumption, it omits unrelated parts of long lines. like:
//
// 1. one long line, short region
// ```
// |
// 1 | ... "foo", "bar", baz, "qux", "foobar", ...
// | ^-- unknown value
// ```
// 2. long region
// ```
// |
// 1 | array = [ "foo", ... "bar" ]
// | ^^^^^^^^^^^^^^^^^^^^- in this array
// ```
// 3. many lines
// |
// 1 | array = [ "foo",
// | ^^^^^^^^
// | ...
// | ^^^
// |
// 10 | , "bar"]
// | ^^^^^^^^- in this array
// ```
//
struct source_location
{
public:
Expand Down Expand Up @@ -39,13 +66,19 @@ struct source_location

std::vector<std::string> const& lines() const noexcept {return line_str_;}

// for internal use
std::size_t first_column_offset() const noexcept {return this->first_offset_;}
std::size_t last_column_offset() const noexcept {return this->last_offset_;}

private:

bool is_ok_;
std::size_t first_line_;
std::size_t first_column_;
std::size_t first_column_; // column num in the actual file
std::size_t first_offset_; // column num in the shown line
std::size_t last_line_;
std::size_t last_column_;
std::size_t last_column_; // column num in the actual file
std::size_t last_offset_; // column num in the shown line
std::size_t length_;
std::string file_name_;
std::vector<std::string> line_str_;
Expand Down
91 changes: 37 additions & 54 deletions include/toml11/impl/location_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ TOML11_INLINE void location::advance(std::size_t n) noexcept
assert(this->is_ok());
if(this->location_ + n < this->source_->size())
{
this->advance_line_number(n);
this->location_ += n;
this->advance_impl(n);
}
else
{
this->advance_line_number(this->source_->size() - this->location_);
this->location_ = this->source_->size();
this->advance_impl(this->source_->size() - this->location_);

assert(this->location_ == this->source_->size());
}
}
TOML11_INLINE void location::retrace(std::size_t n) noexcept
TOML11_INLINE void location::retrace(/*restricted to n=1*/) noexcept
{
assert(this->is_ok());
if(this->location_ < n)
if(this->location_ == 0)
{
this->location_ = 0;
this->line_number_ = 1;
this->column_number_ = 1;
}
else
{
this->retrace_line_number(n);
this->location_ -= n;
this->retrace_impl();
}
}

Expand Down Expand Up @@ -66,30 +66,6 @@ TOML11_INLINE location::char_type location::peek()
}
}

TOML11_INLINE void location::set_location(const std::size_t loc) noexcept
{
if(this->location_ == loc)
{
return ;
}

if(loc == 0)
{
this->line_number_ = 1;
}
else if(this->location_ < loc)
{
const auto d = loc - this->location_;
this->advance_line_number(d);
}
else
{
const auto d = this->location_ - loc;
this->retrace_line_number(d);
}
this->location_ = loc;
}

TOML11_INLINE std::string location::get_line() const
{
assert(this->is_ok());
Expand All @@ -101,7 +77,8 @@ TOML11_INLINE std::string location::get_line() const

return make_string(std::next(prev.base()), next);
}
TOML11_INLINE std::size_t location::column_number() const noexcept

TOML11_INLINE std::size_t location::calc_column_number() const noexcept
{
assert(this->is_ok());
const auto iter = std::next(this->source_->cbegin(), static_cast<difference_type>(this->location_));
Expand All @@ -112,38 +89,44 @@ TOML11_INLINE std::size_t location::column_number() const noexcept
return static_cast<std::size_t>(std::distance(prev.base(), iter) + 1); // 1-origin
}


TOML11_INLINE void location::advance_line_number(const std::size_t n)
TOML11_INLINE void location::advance_impl(const std::size_t n)
{
assert(this->is_ok());
assert(this->location_ + n <= this->source_->size());

const auto iter = this->source_->cbegin();
this->line_number_ += static_cast<std::size_t>(std::count(
std::next(iter, static_cast<difference_type>(this->location_)),
std::next(iter, static_cast<difference_type>(this->location_ + n)),
char_type('\n')));
auto iter = this->source_->cbegin();
std::advance(iter, static_cast<difference_type>(this->location_));

for(std::size_t i=0; i<n; ++i)
{
const auto c = *iter;
if(c == char_type('\n'))
{
this->line_number_ += 1;
this->column_number_ = 1;
}
else
{
this->column_number_ += 1;
}
iter++;
}
this->location_ += n;
return;
}
TOML11_INLINE void location::retrace_line_number(const std::size_t n)
TOML11_INLINE void location::retrace_impl(/*n == 1*/)
{
assert(this->is_ok());
assert(n <= this->location_); // loc - n >= 0
assert(this->location_ != 0);

const auto iter = this->source_->cbegin();
const auto dline_num = static_cast<std::size_t>(std::count(
std::next(iter, static_cast<difference_type>(this->location_ - n)),
std::next(iter, static_cast<difference_type>(this->location_)),
char_type('\n')));
this->location_ -= 1;

if(this->line_number_ <= dline_num)
{
this->line_number_ = 1;
}
else
auto iter = this->source_->cbegin();
std::advance(iter, static_cast<difference_type>(this->location_));
if(*iter == '\n')
{
this->line_number_ -= dline_num;
this->line_number_ -= 1;
this->column_number_ = this->calc_column_number();
}
return;
}
Expand All @@ -166,7 +149,7 @@ TOML11_INLINE bool operator!=(const location& lhs, const location& rhs)
TOML11_INLINE location prev(const location& loc)
{
location p(loc);
p.retrace(1);
p.retrace();
return p;
}
TOML11_INLINE location next(const location& loc)
Expand Down
Loading

0 comments on commit 0f6e08f

Please sign in to comment.