From a92edd5f723d56a377905c91bb6321790d0d3a98 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 27 May 2019 18:19:24 +0200 Subject: Add String and XML helpers --- modules/str.inc | 26 ++++++++++++++++++++++++++ modules/xml.inc | 6 ++++++ 2 files changed, 32 insertions(+) create mode 100644 modules/str.inc create mode 100644 modules/xml.inc (limited to 'modules') diff --git a/modules/str.inc b/modules/str.inc new file mode 100644 index 0000000..6179033 --- /dev/null +++ b/modules/str.inc @@ -0,0 +1,26 @@ +#!/bin/ash + +str_trim() { + if [ $# = 0 ]; then + tr '\n' '\r' | sed -r 's/^[[:space:]]+//;s/[[:space:]]+$//' | tr '\r' '\n' + else + printf "%s" "$*" | tr '\n' '\r' | sed -r 's/^[[:space:]]+//;s/[[:space:]]+$//' | tr '\r' '\n' + fi +} + +str_upper() { + if [ $# = 0 ]; then + tr 'a-z' 'A-Z' + else + printf "%s" "$*" | tr 'a-z' 'A-Z' + fi +} + +str_lower() { + if [ $# = 0 ]; then + tr 'A-Z' 'a-z' + else + printf "%s" "$*" | tr 'A-Z' 'a-z' + fi +} + diff --git a/modules/xml.inc b/modules/xml.inc new file mode 100644 index 0000000..4fa4b84 --- /dev/null +++ b/modules/xml.inc @@ -0,0 +1,6 @@ +#!/bin/ash + +xml_get() { + xmlstarlet sel --text --encode utf-8 --template --value-of "$1" "$2" +} + -- cgit v1.2.3-55-g7522