Skip to content

Commit

Permalink
Feat: add some string related Lua functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Oct 5, 2024
1 parent 99af12a commit 8f92581
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ This is a small bug fix release.

### Changelog

- Upd: translations
- Feat: New custom Lua function: mympd.splitlines(), mympd.trim()
- Upd: Translations
- Upd: Mongoose to current master

***
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ lualibs() {
[ "$MYMPD_ENABLE_MYGPIOD" = "ON" ] && cat contrib/lualibs/mympd/40-mygpiod.lua >> "$MYMPD_BUILDDIR/contrib/lualibs/mympd.lua"
cat contrib/lualibs/mympd/50-util.lua >> "$MYMPD_BUILDDIR/contrib/lualibs/mympd.lua"
cat contrib/lualibs/mympd/60-caches.lua >> "$MYMPD_BUILDDIR/contrib/lualibs/mympd.lua"
cat contrib/lualibs/mympd/70-string.lua >> "$MYMPD_BUILDDIR/contrib/lualibs/mympd.lua"
cat contrib/lualibs/mympd/99-end.lua >> "$MYMPD_BUILDDIR/contrib/lualibs/mympd.lua"
echo "Compiling lua libraries"
LUAC=$(command -v luac5.4 2> /dev/null || command -v luac5.3 2> /dev/null || command -v luac 2> /dev/null || true)
Expand Down
22 changes: 22 additions & 0 deletions contrib/lualibs/mympd/70-string.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
--- myMPD string functions
---

--- Trims a string
-- @param str String to trim
-- @return Trimed string
function mympd.trim(str)
return (string.gsub(str, "^%s*(.-)%s*$", "%1"))
end

--- Split string by newline characters and trims the lines
-- @param str String to split
-- @return tables of lines
function mympd.splitlines(str)
local lines = {}
for line in string.gmatch(str, "[^\n]+") do
line = mympd.trim(line)
table.insert(lines, line)
end
return lines
end
2 changes: 2 additions & 0 deletions docs/050-scripting/functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ List of myMPD specific Lua functions.
| [mympd.notify_client](util.md) | Sends a notification to the client. |
| [mympd.notify_partition](util.md) | Sends a notification to all clients in a partition. |
| [mympd.os_capture](system_command.md) | Executes a system command and capture its output. |
| [mympd.splitlines](string.md) | Split string by newline characters and trims the lines. |
| [mympd.tmp_file](diskcache.md) | Generates a random tmp filename for the misc cache. |
| [mympd.trim](string.md) | Removes beginning and ending whitespaces from a string. |
| [mympd.update_mtime](diskcache.md) | Updates the timestamp of a file. |
| [mympd.urldecode](util.md) | Decodes a URL encoded string. |
| [mympd.urlencode](util.md) | URL encodes a string. |
Expand Down
33 changes: 33 additions & 0 deletions docs/050-scripting/functions/string.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: String Functions
---

Some useful string handling functions.

## Splitting strings

Split string by newline characters and trims the lines.

```lua
local lines = mympd.splitlines(str)
```

**Parameters:**

| PARAMETER | TYPE | DESCRIPTION |
| --------- | ---- | ----------- |
| str | string | Multiline string to split. |

## Triming strings

Removes beginning and ending whitespaces from a string.

```lua
local trimed = mympd.trim(str)
```

**Parameters:**

| PARAMETER | TYPE | DESCRIPTION |
| --------- | ---- | ----------- |
| str | string | String to trim. |
28 changes: 14 additions & 14 deletions docs/_includes/translating_status.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
- bg-BG: 1083 missing phrases
- es-AR: fully translated
- es-ES: 950 missing phrases
- es-VE: 938 missing phrases
- fi-FI: 935 missing phrases
- fr-FR: fully translated
- it-IT: fully translated
- ja-JP: fully translated
- ko-KR: fully translated
- nl-NL: fully translated
- pl-PL: 83 missing phrases
- ru-RU: 31 missing phrases
- zh-Hans: fully translated
- zh-Hant: 117 missing phrases
- bg-BG: 1085 missing phrases
- es-AR: 2 missing phrases
- es-ES: 952 missing phrases
- es-VE: 940 missing phrases
- fi-FI: 937 missing phrases
- fr-FR: 2 missing phrases
- it-IT: 2 missing phrases
- ja-JP: 2 missing phrases
- ko-KR: 2 missing phrases
- nl-NL: 2 missing phrases
- pl-PL: 85 missing phrases
- ru-RU: 33 missing phrases
- zh-Hans: 2 missing phrases
- zh-Hant: 119 missing phrases
10 changes: 10 additions & 0 deletions htdocs/js/globales.js
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,16 @@ const LUAfunctions = {
"desc": "Sends a notification to all clients in the current partition.",
"func": "mympd.notify_partition(severity, message)",
"feat": ""
},
"mympd.splitlines": {
"desc": "Split a multiline string in lines.",
"func": "local lines = mympd.splitlines(str)",
"feat": ""
},
"mympd.trim": {
"desc": "Trims a string.",
"func": "local trimed = mympd.trim(str)",
"feat": ""
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/i18n/json/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -1229,5 +1229,7 @@
"tags": "Tags",
"url_resolved": "URL",
"votes": "Stimmen",
"wasapi": "Windows Audio Session API"
"wasapi": "Windows Audio Session API",
"Split a multiline string in lines.": "Teilt einen mehrzeiligen String in einzelne Zeilen.",
"Trims a string.": "Trimt einen String."
}
18 changes: 9 additions & 9 deletions src/i18n/json/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"default": {"desc":"Browser default", "missingPhrases": 0},
"de-DE": {"desc":"Deutsch (de-DE)", "missingPhrases": 0},
"en-US": {"desc":"English (en-US)", "missingPhrases": 0},
"es-AR": {"desc":"Español (es-AR)", "missingPhrases": 0},
"fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 0},
"it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 0},
"ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 0},
"ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 0},
"nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 0},
"pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 83},
"ru-RU": {"desc":"Russian (ru-RU)", "missingPhrases": 31},
"zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 0}
"es-AR": {"desc":"Español (es-AR)", "missingPhrases": 2},
"fr-FR": {"desc":"Français (fr-FR)", "missingPhrases": 2},
"it-IT": {"desc":"Italiano (it-IT)", "missingPhrases": 2},
"ja-JP": {"desc":"日本語 (ja-JP)", "missingPhrases": 2},
"ko-KR": {"desc":"한국어 (ko-KR)", "missingPhrases": 2},
"nl-NL": {"desc":"Nederlands (nl-NL)", "missingPhrases": 2},
"pl-PL": {"desc":"Polish (pl-PL)", "missingPhrases": 85},
"ru-RU": {"desc":"Russian (ru-RU)", "missingPhrases": 33},
"zh-Hans": {"desc":"简体中文 (zh-Hans)", "missingPhrases": 2}
}
2 changes: 2 additions & 0 deletions src/i18n/json/phrases.json
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@
{"term":"Sorting playlist %{plist} failed: %{error}"},
{"term":"Source and destination playlists are the same"},
{"term":"Specify"},
{"term":"Split a multiline string in lines."},
{"term":"Stars"},
{"term":"Start"},
{"term":"Start playback"},
Expand Down Expand Up @@ -941,6 +942,7 @@
{"term":"Trigger"},
{"term":"Trigger name"},
{"term":"Trigger not found"},
{"term":"Trims a string."},
{"term":"Tue"},
{"term":"Type"},
{"term":"Type or select picture"},
Expand Down

0 comments on commit 8f92581

Please sign in to comment.