Skip to content

A C library that simplifies string creation and manipulation. Styled on a C++ string library.

License

Notifications You must be signed in to change notification settings

bogu9821/BString

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BString

A C library that simplifies string creation and manipulation. Styled on a C++ string library.

Example

#include "BString.h"

int main()
{
	// Declare and initialize a BString variable with default parameters.
	BString hello = BStringDefault;
	// Declare an eStringError variable to store error status and create a BString containing "Hello.".
	eStringError error = BStringCreate(&hello, "Hello.");

	// Check if there was an error during BStringCreate.
	// Return value of all functions returning eStringError should be checked.
	if (error != BSTRING_NONE)
	{
		return -1;
	}

	BString world = BStringDefault;
	BStringCreate(&world, "World");

	// Insert "!" at the end of the BString world.
	BStringInsertAt(&world, BStringToView("!"), world.m_size);
	// Replace "." with a space in the hello BString.
	BStringReplace(&hello, BStringToView("."), BStringToView(" "));
	// Join the contents of the world BString to the end of the hello BString.
	BStringJoin(&hello, world);

	// Print the contents of the hello BString.
	BStringPrint(hello);

	// Find the offset of the substring "Wo" in the world BString, starting from index 0.
	const size_t wordOffset = BStringFind(world, "Wo", 0);

	// Check if the substring "Wo" was found in the world BString.
	if (wordOffset != BSTRING_NPOS)
	{
		BString substring = BStringDefault;
		// Extract a substring from the world BString starting from wordOffset with length sizeof("Wo") - 1.
		BStringSubstring(&substring, world, wordOffset, sizeof("Wo") - 1);

		// Concatenate "nderful " and the world BString to the substring BString.
		BStringConcentrate(&substring, BStringToView("nderful "), BStringToView(world));

		BStringPrint(substring);

		// Free the memory allocated for the substring BString.
		BStringFree(&substring);
	}

	// Free the memory allocated for the hello and world BStrings.
	BStringFree(&hello);
	BStringFree(&world);

	return 0;
}

About

A C library that simplifies string creation and manipulation. Styled on a C++ string library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages