GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ChristianPanov/static_string: Experimental compile-time string manipulation C++17 library

BranchesTags
Open more actions menu

Latest commit

 

History

36 Commits
36 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
premake
premake
 
 
static_string/src
static_string/src
 
 
.gitignore
.gitignore
 
 
GenerateProjects.bat
GenerateProjects.bat
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
premake5.lua
premake5.lua
 
 

Repository files navigation

Experimental compile-time string manipulation C++17 library

Install

git clone --recursive https://github.com/ChristianPanov/static_string

Features

  • Written in modern C++17
  • Compile-time
  • std::string-like interface

Usage

Basic Usage

#include "static_string.h"

#include <iostream>

int main()
{
	constexpr cts::static_string<char, 14> str = "Compile-time ";
	constexpr cts::static_string<char, 7> str2 = "string";

	static_assert(str2.size() == 6);
	static_assert(str.empty() == false);
	static_assert(str[1] == 'o');
	static_assert(str.contains("Compile") == true);
	static_assert(str.contains("Runtime") == false);

	static_assert(str + str2 == "Compile-time string");
	static_assert(str != str2);

	std::cout << str + str2 << '\n';

	return 0;
}

NOTE: When initializing the string object on instantiation, the template arguments can be deduced, thus, can be omitted.

Example

#include "static_string.h"

int main()
{
	constexpr cts::static_string str = "Compile-time string";

	return 0;
}

Find Substring

#include "static_string.h"

int main()
{
	constexpr cts::static_string str = "Compile-time string time";

	//By default, the position offset is 0
	static_assert(str.find("time") == 8);

	//Find substring after a given position
	static_assert(str.find<9>("time") == 20);

	static_assert(str.rfind("time") == 20);

	//Find substring after a given position
	static_assert(str.rfind<20>("time") == 8);

	return 0;
}

Return Substring and Reversed Substring

#include "static_string.h"

int main()
{
	constexpr cts::static_string str = "Compile-time string time";

	static_assert(str.substr<0, 6>() == "Compile");
	static_assert(str.substr<str.find("time"), 11>() == "time");

	static_assert(str.rsubstr<str.find("time"), 11>() == "emit");

	return 0;
}

Replace Substring

#include "static_string.h"

int main()
{
	constexpr cts::static_string str = "Compile-time string time";
	constexpr auto replaced = str.replace<str.find("time"), str.find("time") + 4>("REPLACED");

	static_assert(replaced == "Compile-REPLACED string time");

	return 0;
}

Starts With & Ends With

#include "static_string.h"

int main()
{
	constexpr cts::static_string url = "https://cppreference.com";

	static_assert(url.starts_with("https"));
	static_assert(!url.starts_with("ftp"));
	static_assert(url.ends_with(".com"));
	static_assert(!url.ends_with(".org"));

	return 0;
}

About

Experimental compile-time string manipulation C++17 library

Topics

compile-timecppcpp17cpp17-librarylibrarymetaprogrammingstatic-stringstringstring-manipulation

Resources

Readme
MIT license
Activity

Stars

9 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.