Scnlib Versions Save

scanf for modern C++

v2.0.2

2 months ago

Minor fixes:

  • Fix segfault when runtime-parsing {:[^ as a format string.
  • Fix compilation of scan_buffer.cpp on some MSVC versions.
  • Remove stray test/ folder

Full Changelog: https://github.com/eliaskosunen/scnlib/compare/v2.0.1...v2.0.2

v2.0.1

3 months ago

Minor bugfixes

Full Changelog: https://github.com/eliaskosunen/scnlib/compare/v2.0.0...v2.0.1

v2.0.0

3 months ago

Major overhaul, both internally and in terms of the library interface. The library is rewritten in its entirety. See the documentation at https://scnlib.dev/, namely the Migration guide for more details.

The changes below are relative to v1. See CHANGELOG.md for changes relative to v2.0.0-beta.

Major changes include:

  • C++17 is required.
  • Several names are changed to include the scan_ prefix.
  • scn::scan returns the scanned values by value. Output parameters are no longer used.
  • scn::scan now accepts all forward_ranges (v1: bidirectional_range + default- and move constructible).
  • scn::scan returns a view (subrange) into its input, and never takes ownership.
  • Scope is more focused: list operations, ignore, getline, and file have been removed.
  • Support for regular expressions.
  • Better Unicode support.
  • Performance improvements.
  • Completely reworked internals.

Full Changelog: https://github.com/eliaskosunen/scnlib/compare/v2.0.0-beta...v2.0.0

v1.1.3

6 months ago

Expected to be the last release in the v1-branch. Development efforts are now fully directed towards v2.

Features

  • Allow disabling support for individual types with SCN_DISABLE_TYPE_* (#70, thanks @cjvaughter (CJ Vaughter))
    • Also, allow for disabling the fallbacks to std::from_chars and std::strtod when scanning floats
    • This provides possible binary size reductions, and allows better use in e.g. embedded platforms
  • Allow disabling runtime localization with SCN_DISABLE_LOCALE (#71, thanks @cjvaughter (CJ Vaughter))
  • Parse leading + signs in floats (reported in #77)

Fixes

  • Fix scn::wrap(std::string_view&&) being ambiguous on gcc (reported in #83)
  • Fix compiler error in scn::basic_string_view<CharT>::substr (reported in #86)
  • Fix memory safety issues found with ASan and UBsan in small_vector, detail::utf16::validate_next, and detail::get_buffer.
  • Add COMPONENT to CMake install targets (#80, thanks @pawelwod)
  • Fix calculation of SCN_MSVC from _MSC_FULL_VER (#62, thanks @matbech (Mathias Berchtold))
  • Fix MSVC C4146 warning in integer_scanner (#64, thanks @matbech (Mathias Berchtold))
  • Use if constexpr and std::unreachable if available (#61, #78, thanks @matbech (Mathias Berchtold))
  • Improve error messages given from the float parser

v2.0.0-beta

6 months ago

Major overhaul, both internally and in terms of the library interface. The library is rewritten in its entirety. See the documentation (note the new URL: https://v2.scnlib.dev), namely the Migration guide for more details.

This is a beta pre-release. There may still be some bugs. Changes before v2.0.0 proper are possible, but aren't probably going to be major.

Major changes include:

  • C++17 is required.
  • Several names are changed to include the scan_ prefix.
  • scn::scan returns the scanned values by value. Output parameters are no longer used.
  • scn::scan now accepts all forward_ranges (v1: bidirectional_range + default- and move constructible).
  • scn::scan returns a view (subrange) into its input, and never takes ownership.
  • Scope is more focused: list operations, ignore, getline, and file have been removed.
  • Performance improvements
  • Completely reworked internals

v1.1.2

2 years ago
  • Change SCN_VERSION to report the correct version number: 1.1.0 -> 1.1.2 (#57)

v1.1.1

2 years ago
  • Fix issue with values being skipped when using files and file.sync() (#56)
    • Every call to file.sync() needs to be accompanied by a call to reset_begin_iterator() to the result object
    • This is a temporary fix, permanent fix coming in v2.0.0
int i;
auto ret = scn::scan(scn::cstdin(), "{}", i);
scn::cstdin().sync();
ret.range().reset_begin_iterator();

// Not necessary with input and prompt
ret = scn::input("{}", i);

v1.1

2 years ago
  • Add support for scanning 8-bit integers ((un)signed char, (u)int8_t), and characters (char, wchar_t) as integers
int8_t i1, i2;
char c1, c2;
auto ret = scn::scan("1 2 3 4", "{} {:c} {} {:i}", i1, i2, i3, i4);
// ret == true
// i1 == 1
// i2 == '2'
// c1 == '3'
// c2 == 4
  • Fix usage of external fast_float in CMake (#53, thanks @xvitaly (Vitaly Zaitsev))
  • Fix tests on big endian architectures (#54)
  • Fix alignment issues with small_vector on 32-bit architectures

Full Changelog: https://github.com/eliaskosunen/scnlib/compare/v1.0...v1.1

v1.0

2 years ago

First stable release!

The library is now deemed production-ready, and backwards-compatibility will be maintained until the next major release comes out, in accordance to semantic versioning. 1.x-versions will be getting security updates after that, until further notice.

If you're migrating from v1.0-rc1, no major changes have been made, only bugfixes.

If you're migrating from v0.4, see the migration guide v0.4 -> v1.0.

If you're new here, see the documentation and the repository.

The feature highlights below are the same compared to those of v1.0-rc1

Feature highlights

New float parsing

Now, by default, scnlib uses https://github.com/fastfloat/fast_float for parsing floating-point values, falling back on std::from_chars and std::strtod only if necessary.

This provides even more performance than before: using scn::scan is now 2x to 8x faster than using std::stringstream, when parsing floats.

New format strings

Many things have changed (see the migration guide above), and the same format strings may now do different things.

// alignment
int i{};
auto result = scn::scan("***1***", "{:*^}", i);
// i == 1
// result.empty() == true

// localization
double d{};
result = scn::scan_localized(std::locale{"fi_FI.UTF-8"}, "3,14", "{:L}", d);
// d == 3.14
// result.empty() == true

// width
std::string str1;
result = scn::scan("abcde", "{:3}", str1);
// str1 == "abc"
// result.range() == "de"

// string set
std::string str2;
result = scn::scan("123abc", "{:[0-9]}", str2);
// str2 == "123"
// result.range() == "abc"

Unicode support

// Parse Unicode code points
scn::code_point cp{};
auto result = scn::scan("äa", "{}", cp);
// cp == 0xe4
// result.range() == "a"

// Parse Unicode strings
std::string s1, s2;
// s1: read until whitespace
// s2: read until non-letter character, according to locale
result = scn::scan_localized(std::locale{"fi_FI.UTF-8"}, "äa1 äa1", "{} {:L[:alpha:]}", s1, s2);
// s1 == "äa1"
// s2 == "äa"
// result.range() == "1"

And more

See CHANGELOG.md and the documentation for more details

Full Changelog (from v1.0-rc1): https://github.com/eliaskosunen/scnlib/compare/v1.0-rc1...v1.0

v1.0-rc1

2 years ago

Getting closer to 1.0!

Feature highlights

New float parsing

Now, by default, scnlib uses https://github.com/fastfloat/fast_float for parsing floating-point values, falling back on std::from_chars and std::strtod only if necessary.

This provides even more performance than before.

New format strings

Many things have changed (see the migration guide below), and the same format strings may now do different things.

// alignment
int i{};
auto result = scn::scan("***1***", "{:*^}", i);
// i == 1
// result.empty() == true

// localization
double d{};
result = scn::scan_localized(std::locale{"fi_FI.UTF-8"}, "3,14", "{:L}", d);
// d == 3.14
// result.empty() == true

// width
std::string str1;
result = scn::scan("abcde", "{:3}", str1);
// str1 == "abc"
// result.range() == "de"

// string set
std::string str2;
result = scn::scan("123abc", "{:[0-9]}", str2);
// str2 == "123"
// result.range() == "abc"

Unicode support

// Parse Unicode code points
scn::code_point cp{};
auto result = scn::scan("äa", "{}", cp);
// cp == 0xe4
// result.range() == "a"

// Parse Unicode strings
std::string s1, s2;
// s1: read until whitespace
// s2: read until non-letter character, according to locale
result = scn::scan_localized(std::locale{"fi_FI.UTF-8"}, "äa äa", "{} {:L[:alpha:]}", s1, s2);
// s1 == s2 == "äa"
// result.empty() == true

And more

See CHANGELOG.md and the documentation, namely the migration guide for more details

Full Changelog: https://github.com/eliaskosunen/scnlib/compare/v0.4...v1.0-rc1