Skip to content

Commit

Permalink
all tests ok
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Paulo Magalhaes committed Jan 27, 2024
1 parent 3f8d8e5 commit 6e7b5bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
21 changes: 9 additions & 12 deletions src/c4/yml/filter_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,20 @@ struct FilterProcessorSrcDst
// filter in place

// debugging scaffold
#if 0
#define _c4dbgip(...) _c4dbgpf(__VA_ARGS__);
#if defined(RYML_DBG) && 1
#define _c4dbgip(...) _c4dbgpf(__VA_ARGS__)
#else
#define _c4dbgip(...)
#endif

struct FilterProcessorInplace__
struct FilterProcessorInplaceEndExtending
{
substr src; ///< the subject string
size_t wcap; ///< write capacity - the capacity of the subject string's buffer
size_t rpos; ///< read position
size_t wpos; ///< write position

C4_ALWAYS_INLINE FilterProcessorInplace__(substr src_, size_t wcap_) noexcept
C4_ALWAYS_INLINE FilterProcessorInplaceEndExtending(substr src_, size_t wcap_) noexcept
: src(src_)
, wcap(wcap_)
, rpos(0)
Expand All @@ -149,7 +149,7 @@ struct FilterProcessorInplace__

C4_ALWAYS_INLINE FilterResult result() const noexcept
{
_c4dbgip("inplace: wpos={} wcap={} unfiltered={} maxcap={}", this->wpos, this->wcap, this->unfiltered_chars, this->maxcap);
_c4dbgip("inplace: wpos={} wcap={} small={}", wpos, wcap, wpos > rpos);
FilterResult ret;
ret.str.str = (wpos <= wcap) ? src.str : nullptr;
ret.str.len = wpos;
Expand All @@ -174,23 +174,21 @@ struct FilterProcessorInplace__
}
void set(char c) noexcept
{
RYML_ASSERT(wpos <= rpos);
if(wpos < wcap) // respect write-capacity
src.str[wpos] = c;
++wpos;
}
void set(char c, size_t num) noexcept
{
RYML_ASSERT(num);
RYML_ASSERT(wpos <= rpos);
if(wpos + num <= wcap) // respect write-capacity
memset(src.str + wpos, c, num);
wpos += num;
}

void copy() noexcept
{
RYML_ASSERT(wpos < rpos);
RYML_ASSERT(wpos <= rpos);
RYML_ASSERT(rpos < src.len);
if(wpos < wcap) // respect write-capacity
src.str[wpos] = src.str[rpos];
Expand All @@ -201,7 +199,7 @@ struct FilterProcessorInplace__
{
RYML_ASSERT(num);
RYML_ASSERT(rpos+num <= src.len);
RYML_ASSERT(wpos < rpos);
RYML_ASSERT(wpos <= rpos);
if(wpos + num <= wcap) // respect write-capacity
{
if(wpos + num <= rpos) // there is no overlap
Expand Down Expand Up @@ -241,8 +239,7 @@ struct FilterProcessorInplace__
};


//struct FilterProcessorInplaceExtending
struct FilterProcessorInplaceExtending
struct FilterProcessorInplaceMidExtending
{
substr src; ///< the subject string
size_t wcap; ///< write capacity - the capacity of the subject string's buffer
Expand All @@ -251,7 +248,7 @@ struct FilterProcessorInplaceExtending
size_t maxcap; ///< the max capacity needed for filtering the string. This may be larger than the final string size.
bool unfiltered_chars; ///< number of characters that were not added to wpos from lack of capacity

C4_ALWAYS_INLINE FilterProcessorInplaceExtending(substr src_, size_t wcap_) noexcept
C4_ALWAYS_INLINE FilterProcessorInplaceMidExtending(substr src_, size_t wcap_) noexcept
: src(src_)
, wcap(wcap_)
, rpos(0)
Expand Down
10 changes: 5 additions & 5 deletions src/c4/yml/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4672,7 +4672,7 @@ FilterResult Parser::filter_scalar_plain(csubstr scalar, substr dst, size_t inde

FilterResult Parser::filter_scalar_plain_in_place(substr dst, size_t cap, size_t indentation) noexcept
{
FilterProcessorInplace__ proc(dst, cap);
FilterProcessorInplaceEndExtending proc(dst, cap);
return _filter_plain(proc, indentation);
}

Expand Down Expand Up @@ -4776,7 +4776,7 @@ FilterResult Parser::filter_scalar_squoted(csubstr scalar, substr dst) noexcept

FilterResult Parser::filter_scalar_squoted_in_place(substr dst, size_t cap) noexcept
{
FilterProcessorInplace__ proc(dst, cap);
FilterProcessorInplaceEndExtending proc(dst, cap);
return _filter_squoted(proc);
}

Expand Down Expand Up @@ -5058,7 +5058,7 @@ FilterResult Parser::filter_scalar_dquoted(csubstr scalar, substr dst)

FilterResultExtending Parser::filter_scalar_dquoted_in_place(substr dst, size_t cap)
{
FilterProcessorInplaceExtending proc(dst, cap);
FilterProcessorInplaceMidExtending proc(dst, cap);
return _filter_dquoted(proc);
}

Expand Down Expand Up @@ -5398,7 +5398,7 @@ FilterResult Parser::filter_scalar_block_literal(csubstr scalar, substr dst, siz

FilterResult Parser::filter_scalar_block_literal_in_place(substr scalar, size_t cap, size_t indentation, BlockChomp_e chomp) noexcept
{
FilterProcessorInplace__ proc(scalar, cap);
FilterProcessorInplaceEndExtending proc(scalar, cap);
return _filter_block_literal(proc, indentation, chomp);
}

Expand Down Expand Up @@ -5631,7 +5631,7 @@ FilterResult Parser::filter_scalar_block_folded(csubstr scalar, substr dst, size

FilterResult Parser::filter_scalar_block_folded_in_place(substr scalar, size_t cap, size_t indentation, BlockChomp_e chomp) noexcept
{
FilterProcessorInplace__ proc(scalar, cap);
FilterProcessorInplaceEndExtending proc(scalar, cap);
return _filter_block_folded(proc, indentation, chomp);
}

Expand Down

0 comments on commit 6e7b5bb

Please sign in to comment.