Design Pattern Examples
Overview of object-oriented design patterns
replace.c File Reference

Implementation of various helper functions for replacing characters or strings in a string. More...

#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "replace.h"
#include "strstri.h"
Include dependency graph for replace.c:

Go to the source code of this file.

Functions

void replace_chr (char *s, char c1, char c2)
 Replace all occurrences of narrow character c1 with narrow character c2 in s, using case-sensitive search. If c2 is '\0' then all matches to c1 are effectively removed from the string.
 
void replace_chri (char *s, char c1, char c2)
 Replace all occurrences of narrow character c1 with narrow character c2 in s, using case-insensitive search. If c2 is '\0' then all matches to c1 are effectively removed from the string.
 
static void _append_range (char **buffer, const char *start, const char *end)
 Helper function to append a range of characters to a string that may need to be resized to accommodate the range of characters.
 
char * replace_str (const char *s, const char *str1, const char *str2)
 Replace all occurrences of narrow string str1 with narrow string str2 in s, using case-sensitive search, returning a new string.
 
char * replace_stri (const char *s, const char *str1, const char *str2)
 Replace all occurrences of narrow string str1 with narrow string str2 in s, using case-insensitive search, returning a new string.
 

Detailed Description

Implementation of various helper functions for replacing characters or strings in a string.

Definition in file replace.c.

Function Documentation

◆ _append_range()

static void _append_range ( char **  buffer,
const char *  start,
const char *  end 
)
static

Helper function to append a range of characters to a string that may need to be resized to accommodate the range of characters.

Parameters
bufferPointer to a pointer to a character string. This will contain the pointer to the updated string on return.
startPointer to first character of range to copy.
endPointer to one after last character of range to copy. Must be greater than or equal to start and must point into the same string.

Definition at line 93 of file replace.c.

Referenced by replace_str(), and replace_stri().

◆ replace_chr()

void replace_chr ( char *  s,
char  c1,
char  c2 
)

Replace all occurrences of narrow character c1 with narrow character c2 in s, using case-sensitive search. If c2 is '\0' then all matches to c1 are effectively removed from the string.

Parameters
sString to modify
c1Character to replace
c2Character to replace with

Definition at line 17 of file replace.c.

Referenced by Composite_FileAccess_GetEntry().

◆ replace_chri()

void replace_chri ( char *  s,
char  c1,
char  c2 
)

Replace all occurrences of narrow character c1 with narrow character c2 in s, using case-insensitive search. If c2 is '\0' then all matches to c1 are effectively removed from the string.

Parameters
sString to modify
c1Character to replace
c2Character to replace with

Definition at line 51 of file replace.c.

◆ replace_str()

char * replace_str ( const char *  s,
const char *  str1,
const char *  str2 
)

Replace all occurrences of narrow string str1 with narrow string str2 in s, using case-sensitive search, returning a new string.

Parameters
sString to modify
str1String to replace
str2String to replace with (can be an empty string to remove str1).
Returns
Returns a new string containing the modifications. The string must be released using free()

Definition at line 127 of file replace.c.

References _append_range().

Referenced by Command_Operation_Replace(), and Memento_Operation_Replace().

◆ replace_stri()

char * replace_stri ( const char *  s,
const char *  str1,
const char *  str2 
)

Replace all occurrences of narrow string str1 with narrow string str2 in s, using case-insensitive search, returning a new string.

Parameters
sString to modify
str1String to replace
str2String to replace with (can be an empty string to remove str1).
Returns
Returns a new string containing the modifications. The string must be released using free()

Definition at line 163 of file replace.c.

References _append_range(), and strstri().