lipsum-cpp 0.5.4
A basic library written in C++ for generating placeholder Lorem Ipsum text.
Loading...
Searching...
No Matches
lipsum_h.cpp File Reference

Contains the definitions of all the C wrapper's functions. More...

#include <cstring>
#include <lipsum.h>
#include <lipsum.hpp>
#include "lipsumc/binded.inl"

Macros

#define LPSM_CPPIFY(x, type)

Functions

char * lpsm_GenerateDefaultLipsumSentence (void)
 Generate the beginning Lorem Ipsum sentence.
const char * lpsm_internal_Version__ ()
 Return the current version of lipsum-cpp.
int lpsm_CountWords (const char *str)
 Count the number of words in a string.
int lpsm_CountSentenceFragments (const char *str)
 Count the number of sentence fragments in a string.
int lpsm_CountSentences (const char *str)
 Count the number of sentences in a string.
int lpsm_CountParagraphs (const char *str, lpsm_Format format)
 Count the number of paragraphs or elements in a string.
char * lpsm_ConvertFormat (const char *str, lpsm_Format format1, lpsm_Format format2)
 Convert a string between two formats.
void lpsm_DeleteString (char *str)
 Delete a string returned by a function.

Detailed Description

Contains the definitions of all the C wrapper's functions.

This file defines all the functions declared in lipsum.h. This file is under the BSD Zero-Clause License.

Author
LambBread from github.com

Macro Definition Documentation

◆ LPSM_CPPIFY

#define LPSM_CPPIFY ( x,
type )
Value:
(reinterpret_cast<type*>((x)))

Function Documentation

◆ lpsm_ConvertFormat()

char * lpsm_ConvertFormat ( const char * str,
lpsm_Format format1,
lpsm_Format format2 )

Convert a string between two formats.

Since
0.5.4

Attempt a conversion of a string between the two specified formats.

Parameters
strThe string inputted.
format1The string's format.
format2The destination format.
Returns
char* The converted string.

◆ lpsm_CountParagraphs()

int lpsm_CountParagraphs ( const char * str,
lpsm_Format format )

Count the number of paragraphs or elements in a string.

Since
0.4.6

Count the number of tab characters in a non-formatted string, double newlines in Markdown/HTML strings, and elements in HTML strings.

Parameters
strThe string inputted.
formatThe format the string is in.
Returns
int The number of paragraphs.

◆ lpsm_CountSentenceFragments()

int lpsm_CountSentenceFragments ( const char * str)

Count the number of sentence fragments in a string.

Since
0.4.6

Count the number of commas, semicolons, and hyphens in a string, excluding usage in Markdown. (i.e. hyphen at start of line, or in parentheses)

Parameters
strThe string inputted.
Returns
int The number of sentence fragments.

◆ lpsm_CountSentences()

int lpsm_CountSentences ( const char * str)

Count the number of sentences in a string.

Since
0.3.0

Count the number of periods in a string, ignoring usage in Markdown URLs.

Parameters
strThe string inputted.
Returns
int The number of sentences.

◆ lpsm_CountWords()

int lpsm_CountWords ( const char * str)

Count the number of words in a string.

Count the number of words in a string using a naive approach. It counts some Markdown formatting as words.

Since
0.3.8
Parameters
strThe string inputted.
Returns
int The number of words.

◆ lpsm_DeleteString()

void lpsm_DeleteString ( char * str)

Delete a string returned by a function.

Since
0.0.8

Since pointers allocated with new[] cannot be deallocated with free(), this function handles the deallocation.

Warning
Do not call this function twice on the same string or use the string after deleting, as that would cause a double free or use-after-free and potentially crash the program.
Parameters
strThe string to delete.

◆ lpsm_GenerateDefaultLipsumSentence()

char * lpsm_GenerateDefaultLipsumSentence ( void )

Generate the beginning Lorem Ipsum sentence.

Since
0.0.5

Returns the sentence "Lorem ipsum dolor sit amet, consectetur adipiscing elit."

Note
This function returns a heap-allocated char* which should be deleted with lpsm_DeleteString().
Warning
Do not use a string returned from this function after deleting it with lpsm_DeleteString() or call lpsm_DeleteString() on it twice, as this will cause a use-after-free or double-free and potentially crash your program.
Returns
char* The default Lorem Ipsum sentence.

◆ lpsm_internal_Version__()

const char * lpsm_internal_Version__ ( )

Return the current version of lipsum-cpp.

Since
0.5.4

Return the current version of lipsum-cpp, intended for wrappers.

Returns
const char* The version of lipsum-cpp.