tools

various tools
git clone git://deadbeef.fr/tools.git
Log | Files | Refs | README | LICENSE

commit 198ea2e013f8995f8878969a602f4b06475c025a
parent 26b73340df0c17ea2d58e65d39ff1cdf13a07caf
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date:   Thu, 24 Dec 2020 12:38:39 +0100

btl: added find_unescaped functions

Diffstat:
Mbtl/src/utils.hpp | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/btl/src/utils.hpp b/btl/src/utils.hpp @@ -71,4 +71,28 @@ int esc_fputs( const char *s, FILE *stream ); // be null-terminated. inline int ungets( char const* const str, size_t str_sz ); +inline uint16_t find_unescaped( int end, int esc, char ** str, size_t str_sz ) +{ + char* ch = *str; + + for( ; str_sz != 0 && *ch && *ch != end; ++ch, --str_sz ) + { + if( *ch == esc ) + { + ++ch; + } + } + char* start = *str; + *str = ch; + assert( ch >= start ); + return static_cast<uint16_t>( ch - start ); +} + +inline uint16_t find_unescaped( int end, int esc, char ** str ) +{ + //specific implementation would be faster, since less + //comparison to do, but for now, let's code faster. + return find_unescaped( end, esc, str, strlen( *str ) ); +} + #endif