TinyMUSH 3.3
TinyMUSH Server
|
String utilities. More...
#include "config.h"
#include "constants.h"
#include "typedefs.h"
#include "macros.h"
#include "externs.h"
#include "prototypes.h"
#include <stdbool.h>
#include <ctype.h>
#include <string.h>
Functions | |
char * | ansiChar (int ch) |
Convert ansi character code (x?) to ansi sequence. More... | |
int | ansiNum (int ch) |
Convert ansi character code (x?) to numeric values. More... | |
char | ansiLetter (int num) |
Convert ansi numeric values to character code (x?). More... | |
char | ansiMushCode (int num, bool bg) |
int | ansiBitsMask (int num) |
ANSI packed state definitions – number-to-bitmask translation table. More... | |
int | ansiBits (int num) |
ANSI packed state definitions – number-to-bitvalue translation table. More... | |
char * | level_ansi (const char *s, bool ansi, bool xterm, bool truecolors) |
Go to a string and convert ansi to the lowest supported level. More... | |
char * | strip_ansi (const char *s) |
Return a new string with ansi escape codes removed. More... | |
char * | strip_xterm (char *s) |
Return a new string with xterm color code removed. More... | |
char * | strip_24bit (char *s) |
int | strip_ansi_len (const char *s) |
Count non-escape-code characters. More... | |
char * | normal_to_white (const char *raw) |
This function implements the NOBLEED flag. More... | |
char * | ansi_transition_esccode (int ansi_before, int ansi_after) |
Handle the transition between two ansi sequence. More... | |
char * | ansi_transition_mushcode (int ansi_before, int ansi_after) |
Handle the transition between two ansi sequence of mushcode. More... | |
char * | ansi_transition_letters (int ansi_before, int ansi_after) |
Handle the transition between two ansi sequence of mushcode. More... | |
int | ansi_map_states (const char *s, int **m, char **p) |
Identify ansi state of every character in a string. More... | |
char * | remap_colors (const char *s, int *cmap) |
Allow a change of the color sequences. More... | |
char * | translate_string (char *str, int type) |
Convert raw ansi to mushcode or strip it. More... | |
int | rgb2xterm (long rgb) |
Convert an RGB value to xterm value. More... | |
int | str2xterm (char *str) |
Convert a value to xterm color. More... | |
char * | upcasestr (char *s) |
Capitalizes an entire string. More... | |
char * | munge_space (char *string) |
Compress multiple spaces into one and remove leading/trailing spaces. More... | |
char * | trim_spaces (char *string) |
Remove leading and trailing spaces. More... | |
char * | grabto (char **str, char targ) |
Return portion of a string up to the indicated character. More... | |
int | string_compare (const char *s1, const char *s2) |
Compare two string. Treat multiple spaces as one. More... | |
int | string_prefix (const char *string, const char *prefix) |
Compare a string with a prefix. More... | |
const char * | string_match (const char *src, const char *sub) |
Compare a string with a substring, accepts only nonempty matches starting at the beginning of a word. More... | |
char * | replace_string (const char *old, const char *new, const char *string) |
Replace all occurences of a substring with a new substring. More... | |
void | edit_string (char *src, char **dst, char *from, char *to) |
Replace all occurences of a substring with a new substring. Sensitive about ANSI codes, and handles special ^ and $ cases. More... | |
int | minmatch (char *str, char *target, int min) |
Find if a substring at the start of a string exist. More... | |
int | matches_exit_from_list (char *exit_list, char *pattern) |
Find if pattern is found in the exit list. More... | |
char * | ltos (long num) |
char * | repeatchar (int count, char ch) |
Return a string with 'count' number of 'ch' characters. More... | |
void | skip_esccode (char **s) |
Move the pointer after an ansi escape sequence. More... | |
void | copy_esccode (char **s, char **t) |
Copy the ansi sequence into another pointer. More... | |
void | safe_copy_esccode (char **s, char *buff, char **bufc) |
Copy the ansi sequence into another pointer, moving bufc to the end of the receiving buffer and watching for overflow. More... | |
void | track_ansi_letters (char *t, int *ansi_state) |
Convert mushcode to ansi state. More... | |
String utilities.
int ansi_map_states | ( | const char * | s, |
int ** | m, | ||
char ** | p | ||
) |
Identify ansi state of every character in a string.
It is the responsibility of the caller to free m with XFREE(m, "ansi_map_states_ansi_map") and p with XFREE(p, "ansi_map_states_stripped");
s | Pointer to the string to be mapped. |
m | Pointer to the ansi map to be build. |
p | Pointer to the mapped string. |
char * ansi_transition_esccode | ( | int | ansi_before, |
int | ansi_after | ||
) |
Handle the transition between two ansi sequence.
It is the responsibility of the caller to free the returning buffer with XFREE();
ansi_before | Ansi state before transition. |
ansi_after | ansi state after transition. |
char * ansi_transition_letters | ( | int | ansi_before, |
int | ansi_after | ||
) |
Handle the transition between two ansi sequence of mushcode.
It is the responsibility of the caller to free the returning buffer with XFREE();
ansi_before | Ansi state before transition. |
ansi_after | ansi state after transition. |
char * ansi_transition_mushcode | ( | int | ansi_before, |
int | ansi_after | ||
) |
Handle the transition between two ansi sequence of mushcode.
It is the responsibility of the caller to free the returning buffer with XFREE();
ansi_before | Ansi state before transition. |
ansi_after | ansi state after transition. |
int ansiBits | ( | int | num | ) |
ANSI packed state definitions – number-to-bitvalue translation table.
ANSI packed state definitions – number-to-bitvalue translation
num | ANSI number |
int ansiBitsMask | ( | int | num | ) |
ANSI packed state definitions – number-to-bitmask translation table.
The mask specifies the state bits that are altered by a particular ansi code. Bits are laid out as follows:
0x1000 – No ansi. Every valid ansi code clears this bit. 0x0800 – inverse 0x0400 – flash 0x0200 – underline 0x0100 – highlight 0x0080 – "use default bg", set by ansi normal, cleared by other bg's 0x0070 – three bits of bg color 0x0008 – "use default fg", set by ansi normal, cleared by other fg's 0x0007 – three bits of fg color
ANSI packed state definitions – number-to-bitmask translation
The mask specifies the state bits that are altered by a particular ansi code. Bits are laid out as follows:
0x2000 – Bright color flags 0x1000 – No ansi. Every valid ansi code clears this bit. 0x0800 – inverse 0x0400 – flash 0x0200 – underline 0x0100 – highlight 0x0080 – "use default bg", set by ansi normal, cleared by other bg's 0x0070 – three bits of bg color 0x0008 – "use default fg", set by ansi normal, cleared by other fg's 0x0007 – three bits of fg color
num | ANSI number |
char * ansiChar | ( | int | ch | ) |
Convert ansi character code (x?) to ansi sequence.
ch | Character to convert |
char ansiLetter | ( | int | num | ) |
Convert ansi numeric values to character code (x?).
num | ANSI number |
int ansiNum | ( | int | ch | ) |
Convert ansi character code (x?) to numeric values.
ch | ANSI character |
void copy_esccode | ( | char ** | s, |
char ** | t | ||
) |
Copy the ansi sequence into another pointer.
s | Pointer containing the ansi sequence. |
t | Pointer who will receive the ansi sequence. |
void edit_string | ( | char * | src, |
char ** | dst, | ||
char * | from, | ||
char * | to | ||
) |
Replace all occurences of a substring with a new substring. Sensitive about ANSI codes, and handles special ^ and $ cases.
src | Pointer to the original string. |
dst | Pointer to the new string. |
from | Pointer to the string to be replaced |
to | Pointer to the string to be replaced with. |
char * grabto | ( | char ** | str, |
char | targ | ||
) |
Return portion of a string up to the indicated character.
Note that str will be move to the position following the searched character. If you need the original string, save it before calling this function.
str | The string you want to search |
targ | The caracter you want to search for, |
char * level_ansi | ( | const char * | s, |
bool | ansi, | ||
bool | xterm, | ||
bool | truecolors | ||
) |
Go to a string and convert ansi to the lowest supported level.
s | String to convert |
ansi | Player support ansi |
xterm | Player support xterm colors |
truecolors | Player system support true colors |
int matches_exit_from_list | ( | char * | exit_list, |
char * | pattern | ||
) |
Find if pattern is found in the exit list.
exit_list | Pointer to the list of names of an exit |
pattern | Pointer to the pattern we are searching |
int minmatch | ( | char * | str, |
char * | target, | ||
int | min | ||
) |
Find if a substring at the start of a string exist.
At least MIN characters must match. This is how flags are match by the command queue.
str | Pointer to the string that will be search. |
target | Pointer to the string being search. |
min | Minimum length of match. |
char * munge_space | ( | char * | string | ) |
Compress multiple spaces into one and remove leading/trailing spaces.
It is the responsibility of the caller to free the returned buffer with XFREE().
s | The string that need to be munge |
char * normal_to_white | ( | const char * | raw | ) |
This function implements the NOBLEED flag.
It is the responsibility of the caller to free the returned buffer with XFREE().
raw | Pointer to the string who need to be ansi terminated. |
char * remap_colors | ( | const char * | s, |
int * | cmap | ||
) |
Allow a change of the color sequences.
It is the responsibility of the caller to free the returned buffer with XFREE().
s | Pointer to the string to be remap. |
m | Pointer to the ansi color map to use. |
char * repeatchar | ( | int | count, |
char | ch | ||
) |
Return a string with 'count' number of 'ch' characters.
It is the responsibility of the caller to free the resulting buffer.
count | Length of the string to build |
ch | Character used to fill the string. |
char * replace_string | ( | const char * | old, |
const char * | new, | ||
const char * | string | ||
) |
Replace all occurences of a substring with a new substring.
old | The string you want to replace. |
new | The string you want to replace with. |
string | The string that is modified. |
int rgb2xterm | ( | long | rgb | ) |
Convert an RGB value to xterm value.
rgb | Color to convert to xterm value |
void safe_copy_esccode | ( | char ** | s, |
char * | buff, | ||
char ** | bufc | ||
) |
Copy the ansi sequence into another pointer, moving bufc to the end of the receiving buffer and watching for overflow.
s | Pointer containing the ansi sequence. |
buff | Pointer to the receiving buffer. |
bufc | Pointer to where the data will be copied into the receiving buffer. |
void skip_esccode | ( | char ** | s | ) |
Move the pointer after an ansi escape sequence.
s | Pointer that need to be modified. |
int str2xterm | ( | char * | str | ) |
Convert a value to xterm color.
str | A string representing the color to be convert into xterm value. The value can be express as hex (#rrggbb), decimal (r g b). a 24 bit integer value, or the actual xterm value. |
int string_compare | ( | const char * | s1, |
const char * | s2 | ||
) |
Compare two string. Treat multiple spaces as one.
s1 | The first string to compare |
s2 | The second string to compare |
const char * string_match | ( | const char * | src, |
const char * | sub | ||
) |
Compare a string with a substring, accepts only nonempty matches starting at the beginning of a word.
src | The string you want to search |
sub | The search term. |
int string_prefix | ( | const char * | string, |
const char * | prefix | ||
) |
Compare a string with a prefix.
string | The string you want to search |
prefix | The prefix you are searching for. |
char * strip_ansi | ( | const char * | s | ) |
Return a new string with ansi escape codes removed.
It is the responsibility of the caller to free the returned buffer with XFREE().
s | Pointer to the original string |
int strip_ansi_len | ( | const char * | s | ) |
Count non-escape-code characters.
s | Pointer to the string. |
char * strip_xterm | ( | char * | s | ) |
Return a new string with xterm color code removed.
It is the responsibility of the caller to free the returned buffer with XFREE().
s | Pointer to the original string |
It is the responsibility of the caller to free the returned buffer with XFREE().
s | Pointer to the original string |
void track_ansi_letters | ( | char * | t, |
int * | ansi_state | ||
) |
Convert mushcode to ansi state.
t | Pointer containing the ansi sequence. |
ansi_state | The ansi state that need to be updated. |
char * translate_string | ( | char * | str, |
int | type | ||
) |
Convert raw ansi to mushcode or strip it.
It is the responsibility of the caller to free the returned buffer with XFREE().
str | Pointer to the string to be translated |
type | 1 = Convert to mushcode, 0 strip ansi. |
char * trim_spaces | ( | char * | string | ) |
Remove leading and trailing spaces.
s | The string that need to be trimmed. |
char * upcasestr | ( | char * | s | ) |
Capitalizes an entire string.
s | The string that need to be capitalized. |