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

C wrapper over lipsum-cpp. More...

#include <stdbool.h>
#include <stdio.h>
#include "lipsumc/binded.h"

Go to the source code of this file.

Typedefs

typedef enum lpsm_Format lpsm_Format
 Types of formats.

Enumerations

enum  lpsm_Format {
  LPSM_FMT_PLAIN = 0 , LPSM_FMT_MARKDOWN , LPSM_FMT_HTML , LPSM_FMT_JSON ,
  LPSM_FMT_XML
}
 Types of formats. More...

Functions

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

Detailed Description

C wrapper over lipsum-cpp.

This contains the C wrapper over lipsum-cpp. It requires being built as a static or shared library in order to function. This file is under the BSD Zero-Clause License.

Author
LambBread from github.com

Typedef Documentation

◆ lpsm_Format

typedef enum lpsm_Format lpsm_Format

Types of formats.

Since
0.4.6

Types of formats used in lpsm_CountParagraphs() and lpsm_ConvertFormat(). In lpsm_CountParagraphs(), LPSM_FMT_PLAIN is counting plain text, LPSM_FMT_MARKDOWN is counting Markdown or HTML, and LPSM_FMT_HTML is counting HTML explicitly. Formerly known as lpsm_CountParaMethod.

Enumeration Type Documentation

◆ lpsm_Format

Types of formats.

Since
0.4.6

Types of formats used in lpsm_CountParagraphs() and lpsm_ConvertFormat(). In lpsm_CountParagraphs(), LPSM_FMT_PLAIN is counting plain text, LPSM_FMT_MARKDOWN is counting Markdown or HTML, and LPSM_FMT_HTML is counting HTML explicitly. Formerly known as lpsm_CountParaMethod.

Function Documentation

◆ lpsm_ConvertFormat()

LIPSUMC_API 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()

LIPSUMC_API 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()

LIPSUMC_API 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()

LIPSUMC_API 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()

LIPSUMC_API 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()

LIPSUMC_API 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.
Examples
CWrapper.c.

◆ lpsm_GenerateDefaultLipsumSentence()

LIPSUMC_API 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__()

LIPSUMC_API 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.
Examples
CWrapper.c.