From 1bb8754dce3997bc7fd873dd5e21f90ca9fe288f Mon Sep 17 00:00:00 2001 From: AlexApps99 Date: Tue, 14 Jan 2020 17:10:19 +1300 Subject: [PATCH] Added lower_case and upper_case commands --- doc/variables.xml | 22 +++++++++++++++++++++- src/core.cc | 6 ++++++ src/misc.cc | 16 ++++++++++++++++ src/misc.h | 2 ++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/doc/variables.xml b/doc/variables.xml index 3cec3d7b..18001005 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -3847,7 +3847,27 @@ - All words capitalized regardless. + Capitalises the start of each word. + + + + + + + + + + Converts all letters into lowercase. + + + + + + + + + + Converts all letters into uppercase. diff --git a/src/core.cc b/src/core.cc index c2a105f7..63d46103 100644 --- a/src/core.cc +++ b/src/core.cc @@ -886,6 +886,12 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, END OBJ(start_case, 0) obj->data.s = STRNDUP_ARG; obj->callbacks.print = &print_cap; obj->callbacks.free = &gen_free_opaque; + END OBJ(lower_case, 0) obj->data.s = STRNDUP_ARG; + obj->callbacks.print = &print_lower; + obj->callbacks.free = &gen_free_opaque; + END OBJ(upper_case, 0) obj->data.s = STRNDUP_ARG; + obj->callbacks.print = &print_upper; + obj->callbacks.free = &gen_free_opaque; END OBJ(catp, 0) obj->data.s = STRNDUP_ARG; obj->callbacks.print = &print_catp; obj->callbacks.free = &gen_free_opaque; diff --git a/src/misc.cc b/src/misc.cc index b447a347..6d5b9b92 100644 --- a/src/misc.cc +++ b/src/misc.cc @@ -108,6 +108,22 @@ void print_cap(struct text_object *obj, char *p, unsigned int p_max_size) { snprintf(p, p_max_size, "%s", buf); } +void print_lower(struct text_object *obj, char *p, unsigned int p_max_size) { + evaluate(obj->data.s, p, p_max_size); + for (unsigned int x = 0; x < p_max_size-1 && p[x]; x++) { + p[x] = tolower(p[x]); + } + p[p_max_size-1] = '\0'; +} + +void print_upper(struct text_object *obj, char *p, unsigned int p_max_size) { + evaluate(obj->data.s, p, p_max_size); + for (unsigned int x = 0; x < p_max_size-1 && p[x]; x++) { + p[x] = toupper(p[x]); + } + p[p_max_size-1] = '\0'; +} + long long int apply_base_multiplier(const char *s, long long int num) { long long int base = 1024LL; if (*s && (0 == (strcmp(s, "si")))) { base = 1000LL; } diff --git a/src/misc.h b/src/misc.h index a1cd7770..7033dbdb 100644 --- a/src/misc.h +++ b/src/misc.h @@ -36,5 +36,7 @@ void print_cat(struct text_object *, char *, unsigned int); void print_catp(struct text_object *, char *, unsigned int); void print_cap(struct text_object *, char *, unsigned int); +void print_lower(struct text_object *, char *, unsigned int); +void print_upper(struct text_object *, char *, unsigned int); long long apply_base_multiplier(const char *, long long int); #endif /* _MISC_H */