Giter Club home page Giter Club logo

cpp-string-utils's Introduction

C++ String Utils

C++17 and C++11 std::string_view-based utils.

to_string

std::string buffer(32, '\0');
std::string_view result = utils::to_string(12.34f, buffer);
assert(!result.empty());
assert(result == "12.34");
std::string buffer(32, '\0');
std::string_view result = utils::to_string(0xDEADBEEF, buffer, true);
assert(!result.empty());
assert(result == "deadbeef");

from_string

float f32 = 0.0f;
assert(utils::from_string("12.34", f32));
assert(f32 == 12.34f);
uint32_t u32 = 0;
assert(utils::from_string("DEADBEEF", u32, true));
assert(u32 == 0xDEADBEEF);
assert(utils::from_string("deadbeef", u32, true));
assert(u32 == 0xDEADBEEF);

trimm

std::string_view result = utils::trimm("\n 12.34 \t");
assert(result == "12.34");

split

utils::split("|12||34|5\\|6|", "|", [](std::string_view part, uint32_t idx) {
    switch (idx) {
    case 0: assert(part == "12"); break;
    case 1: assert(part == "34"); break;
    case 2: assert(part == "5\\|6"); break;
    default: assert(false); break;
    }
});

substr

constexpr std::string_view str = "[email protected]";
uint32_t offset = 0;
std::string_view user = utils::substr(str, offset, "@");
assert(user == "user");
std::string_view email = utils::substr(str, offset, ".");
assert(email == "email");
std::string_view com = utils::substr(str, offset, ".");
assert(com == "com");

cpp-string-utils's People

Contributors

yurablok avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.