From 61a6b22211fdb25c21aadff8762bc4e70688b04c Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Wed, 7 Feb 2024 16:02:09 +0800 Subject: [PATCH] move title escaping code to lua --- CMakeLists.txt | 1 - src/lua/dyn_menu.lua | 58 +++---- src/menu.c | 23 +-- src/mpv/misc/bstr.c | 380 ------------------------------------------- src/mpv/misc/bstr.h | 196 ---------------------- src/mpv/misc/ctype.h | 19 --- 6 files changed, 31 insertions(+), 646 deletions(-) delete mode 100644 src/mpv/misc/bstr.c delete mode 100644 src/mpv/misc/bstr.h delete mode 100644 src/mpv/misc/ctype.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 143b33c..91b1b22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,6 @@ configure_file(${PROJECT_SOURCE_DIR}/menu.rc.in ${PROJECT_BINARY_DIR}/menu.rc @O set(CMAKE_SHARED_LIBRARY_PREFIX "") add_library(menu SHARED - src/mpv/misc/bstr.c src/mpv/misc/dispatch.c src/mpv/ta/ta.c src/mpv/ta/ta_talloc.c diff --git a/src/lua/dyn_menu.lua b/src/lua/dyn_menu.lua index 1cb32c5..f697785 100644 --- a/src/lua/dyn_menu.lua +++ b/src/lua/dyn_menu.lua @@ -8,6 +8,7 @@ local msg = require('mp.msg') -- user options local o = { uosc_syntax = false, -- toggle uosc menu syntax support + escape_title = true, -- escape & to && in menu title max_title_length = 80, -- limit the title length, set to 0 to disable. max_playlist_items = 20, -- limit the playlist items in submenu, set to 0 to disable. } @@ -232,8 +233,8 @@ local function build_track_items(list, type, prop, prefix) local state = {} -- there may be 2 tracks selected at the same time, for example: subtitle if track.selected then - table.insert(state, 'checked') - if track.id ~= pos then table.insert(state, 'disabled') end + state[#state + 1] = 'checked' + if track.id ~= pos then state[#state + 1] = 'disabled' end end items[#items + 1] = { @@ -281,11 +282,11 @@ local function update_tracks_menu(menu) local items_s = build_track_items(track_list, 'sub', 'sid', true) -- append video/audio/sub tracks into one submenu, separated by a separator - for _, item in ipairs(items_v) do table.insert(submenu, item) end - if #submenu > 0 and #items_a > 0 then table.insert(submenu, { type = 'separator' }) end - for _, item in ipairs(items_a) do table.insert(submenu, item) end - if #submenu > 0 and #items_s > 0 then table.insert(submenu, { type = 'separator' }) end - for _, item in ipairs(items_s) do table.insert(submenu, item) end + for _, item in ipairs(items_v) do submenu[#submenu + 1] = item end + if #submenu > 0 and #items_a > 0 then submenu[#submenu + 1] = { type = 'separator' } end + for _, item in ipairs(items_a) do submenu[#submenu + 1] = item end + if #submenu > 0 and #items_s > 0 then submenu[#submenu + 1] = { type = 'separator' } end + for _, item in ipairs(items_s) do submenu[#submenu + 1] = item end end -- handle #@tracks/ menu update for given type @@ -295,7 +296,7 @@ local function update_track_menu(menu, type, prop) if #track_list == 0 then return end local items = build_track_items(track_list, type, prop, false) - for _, item in ipairs(items) do table.insert(submenu, item) end + for _, item in ipairs(items) do submenu[#submenu + 1] = item end end -- handle #@chapters menu update @@ -418,7 +419,7 @@ local function update_menu_state(menu) local state = {} if type(res) == 'string' then - for s in res:gmatch('[^,%s]+') do table.insert(state, s) end + for s in res:gmatch('[^,%s]+') do state[#state + 1] = s end end menu.item.state = state menu_items_dirty = true @@ -456,7 +457,7 @@ local function dyn_menu_load(item, keyword) state = nil, dirty = false, } - table.insert(dyn_menus, menu) + dyn_menus[#dyn_menus + 1] = menu keyword_to_menu[keyword] = menu local expr = keyword:match('^state=(.-)%s*$') @@ -592,9 +593,6 @@ end -- parse input.conf, return menu items local function parse_input_conf(conf) - local items = {} - local by_id = {} - local function extract_title(cmd) if not cmd or cmd == '' then return '' end local title = cmd:match('#menu:%s*(.*)%s*') @@ -620,14 +618,24 @@ local function parse_input_conf(conf) return list end + local function append_menu(menu, type, title, cmd, submenu) + menu[#menu + 1] = { + type = type, + title = (title and o.escape_title) and title:gsub('&', '&&') or title, + cmd = cmd, + submenu = submenu, + } + end + + local items = {} + local by_id = {} + for line in conf:gmatch('[^\r\n]+') do if line:sub(1, 1) ~= '#' or o.uosc_syntax then - local key, cmd = line:match('%s*([%S]+)%s+(.-)%s*$') - local title = extract_title(cmd) - local list = split_title(title) - local submenu_id = '' local target_menu = items + local key, cmd = line:match('%s*([%S]+)%s+(.-)%s*$') + local list = split_title(extract_title(cmd)) for id, name in ipairs(list) do if id < #list then @@ -635,23 +643,15 @@ local function parse_input_conf(conf) if not by_id[submenu_id] then local submenu = {} by_id[submenu_id] = submenu - target_menu[#target_menu + 1] = { - title = name, - type = 'submenu', - submenu = submenu, - } + append_menu(target_menu, 'submenu', name, nil, submenu) end target_menu = by_id[submenu_id] else if name == '-' or (o.uosc_syntax and name:sub(1, 3) == '---') then - target_menu[#target_menu + 1] = { - type = 'separator', - } + append_menu(target_menu, 'separator') else - target_menu[#target_menu + 1] = { - title = (key ~= '' and key ~= '_') and (name .. "\t" .. key) or name, - cmd = cmd, - } + local title = (key ~= '' and key ~= '_') and (name .. "\t" .. key) or name + append_menu(target_menu, nil, title, cmd) end end end diff --git a/src/menu.c b/src/menu.c index 5da62b2..f3c0dd0 100644 --- a/src/menu.c +++ b/src/menu.c @@ -2,28 +2,9 @@ // SPDX-License-Identifier: GPL-2.0-only #include -#include "misc/bstr.h" +#include "mpv_talloc.h" #include "menu.h" -// escape & to && for menu title -static wchar_t *escape_title(void *talloc_ctx, char *title) { - void *tmp = talloc_new(NULL); - bstr left, rest; - bstr escaped = bstr0(NULL); - - left = bstr_split(bstr0(title), "&", &rest); - while (rest.len > 0) { - bstr_xappend(tmp, &escaped, left); - bstr_xappend(tmp, &escaped, bstr0("&&")); - left = bstr_split(rest, "&", &rest); - } - bstr_xappend(tmp, &escaped, left); - - wchar_t *ret = mp_from_utf8(talloc_ctx, bstrdup0(tmp, escaped)); - talloc_free(tmp); - return ret; -} - // append menu item to HMENU static int append_menu(HMENU hmenu, UINT fMask, UINT fType, UINT fState, wchar_t *title, HMENU submenu, void *data) { @@ -135,7 +116,7 @@ static void build_menu(void *talloc_ctx, HMENU hmenu, mpv_node *node) { strcmp(cmd, "ignore") == 0; } int id = append_menu(hmenu, fMask, 0, (UINT)fState, - escape_title(talloc_ctx, title), submenu, + mp_from_utf8(talloc_ctx, title), submenu, talloc_strdup(talloc_ctx, cmd)); if (grayed) EnableMenuItem(hmenu, id, MF_BYCOMMAND | MF_GRAYED); } diff --git a/src/mpv/misc/bstr.c b/src/mpv/misc/bstr.c deleted file mode 100644 index d825b61..0000000 --- a/src/mpv/misc/bstr.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see . - */ - -#include -#include -#include -#include -#include -#include - -#include "mpv_talloc.h" - -#include "misc/ctype.h" -#include "bstr.h" - -#define MPMAX(a, b) ((a) > (b) ? (a) : (b)) -#define MPMIN(a, b) ((a) > (b) ? (b) : (a)) - -int bstrcmp(struct bstr str1, struct bstr str2) -{ - int ret = 0; - if (str1.len && str2.len) - ret = memcmp(str1.start, str2.start, MPMIN(str1.len, str2.len)); - - if (!ret) { - if (str1.len == str2.len) - return 0; - else if (str1.len > str2.len) - return 1; - else - return -1; - } - return ret; -} - -int bstrcasecmp(struct bstr str1, struct bstr str2) -{ - int ret = 0; - if (str1.len && str2.len) - ret = strncasecmp(str1.start, str2.start, MPMIN(str1.len, str2.len)); - - if (!ret) { - if (str1.len == str2.len) - return 0; - else if (str1.len > str2.len) - return 1; - else - return -1; - } - return ret; -} - -int bstrchr(struct bstr str, int c) -{ - for (int i = 0; i < str.len; i++) - if (str.start[i] == c) - return i; - return -1; -} - -int bstrrchr(struct bstr str, int c) -{ - for (int i = str.len - 1; i >= 0; i--) - if (str.start[i] == c) - return i; - return -1; -} - -int bstrcspn(struct bstr str, const char *reject) -{ - int i; - for (i = 0; i < str.len; i++) - if (strchr(reject, str.start[i])) - break; - return i; -} - -int bstrspn(struct bstr str, const char *accept) -{ - int i; - for (i = 0; i < str.len; i++) - if (!strchr(accept, str.start[i])) - break; - return i; -} - -int bstr_find(struct bstr haystack, struct bstr needle) -{ - for (int i = 0; i < haystack.len; i++) - if (bstr_startswith(bstr_splice(haystack, i, haystack.len), needle)) - return i; - return -1; -} - -struct bstr bstr_lstrip(struct bstr str) -{ - while (str.len && mp_isspace(*str.start)) { - str.start++; - str.len--; - } - return str; -} - -struct bstr bstr_rstrip(struct bstr str) -{ - while (str.len && mp_isspace(str.start[str.len - 1])) - str.len--; - return str; -} - -struct bstr bstr_strip(struct bstr str) -{ - str = bstr_lstrip(str); - while (str.len && mp_isspace(str.start[str.len - 1])) - str.len--; - return str; -} - -struct bstr bstr_split(struct bstr str, const char *sep, struct bstr *rest) -{ - int start; - for (start = 0; start < str.len; start++) - if (!strchr(sep, str.start[start])) - break; - str = bstr_cut(str, start); - int end = bstrcspn(str, sep); - if (rest) { - *rest = bstr_cut(str, end); - } - return bstr_splice(str, 0, end); -} - -// Unlike with bstr_split(), tok is a string, and not a set of char. -// If tok is in str, return true, and: concat(out_left, tok, out_right) == str -// Otherwise, return false, and set out_left==str, out_right=="" -bool bstr_split_tok(bstr str, const char *tok, bstr *out_left, bstr *out_right) -{ - bstr bsep = bstr0(tok); - int pos = bstr_find(str, bsep); - if (pos < 0) - pos = str.len; - *out_left = bstr_splice(str, 0, pos); - *out_right = bstr_cut(str, pos + bsep.len); - return pos != str.len; -} - -struct bstr bstr_splice(struct bstr str, int start, int end) -{ - if (start < 0) - start += str.len; - if (end < 0) - end += str.len; - end = MPMIN(end, str.len); - start = MPMAX(start, 0); - end = MPMAX(end, start); - str.start += start; - str.len = end - start; - return str; -} - -long long bstrtoll(struct bstr str, struct bstr *rest, int base) -{ - str = bstr_lstrip(str); - char buf[51]; - int len = MPMIN(str.len, 50); - memcpy(buf, str.start, len); - buf[len] = 0; - char *endptr; - long long r = strtoll(buf, &endptr, base); - if (rest) - *rest = bstr_cut(str, endptr - buf); - return r; -} - -double bstrtod(struct bstr str, struct bstr *rest) -{ - str = bstr_lstrip(str); - char buf[101]; - int len = MPMIN(str.len, 100); - memcpy(buf, str.start, len); - buf[len] = 0; - char *endptr; - double r = strtod(buf, &endptr); - if (rest) - *rest = bstr_cut(str, endptr - buf); - return r; -} - -struct bstr bstr_splitchar(struct bstr str, struct bstr *rest, const char c) -{ - int pos = bstrchr(str, c); - if (pos < 0) - pos = str.len; - if (rest) - *rest = bstr_cut(str, pos + 1); - return bstr_splice(str, 0, pos + 1); -} - -struct bstr bstr_strip_linebreaks(struct bstr str) -{ - if (bstr_endswith0(str, "\r\n")) { - str = bstr_splice(str, 0, str.len - 2); - } else if (bstr_endswith0(str, "\n")) { - str = bstr_splice(str, 0, str.len - 1); - } - return str; -} - -bool bstr_eatstart(struct bstr *s, struct bstr prefix) -{ - if (!bstr_startswith(*s, prefix)) - return false; - *s = bstr_cut(*s, prefix.len); - return true; -} - -bool bstr_eatend(struct bstr *s, struct bstr prefix) -{ - if (!bstr_endswith(*s, prefix)) - return false; - s->len -= prefix.len; - return true; -} - -void bstr_lower(struct bstr str) -{ - for (int i = 0; i < str.len; i++) - str.start[i] = mp_tolower(str.start[i]); -} - -int bstr_sscanf(struct bstr str, const char *format, ...) -{ - char *ptr = bstrdup0(NULL, str); - va_list va; - va_start(va, format); - int ret = vsscanf(ptr, format, va); - va_end(va); - talloc_free(ptr); - return ret; -} - -static void resize_append(void *talloc_ctx, bstr *s, size_t append_min) -{ - size_t size = talloc_get_size(s->start); - assert(s->len <= size); - if (append_min > size - s->len) { - if (append_min < size) - append_min = size; // preallocate in power of 2s - if (size >= SIZE_MAX / 2 || append_min >= SIZE_MAX / 2) - abort(); // oom - s->start = talloc_realloc_size(talloc_ctx, s->start, size + append_min); - } -} - -// Append the string, so that *s = *s + append. s->start is expected to be -// a talloc allocation (which can be realloced) or NULL. -// This function will always implicitly append a \0 after the new string for -// convenience. -// talloc_ctx will be used as parent context, if s->start is NULL. -void bstr_xappend(void *talloc_ctx, bstr *s, bstr append) -{ - if (!append.len) - return; - resize_append(talloc_ctx, s, append.len + 1); - memcpy(s->start + s->len, append.start, append.len); - s->len += append.len; - s->start[s->len] = '\0'; -} - -void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - bstr_xappend_vasprintf(talloc_ctx, s, fmt, ap); - va_end(ap); -} - -// Exactly as bstr_xappend(), but with a formatted string. -void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, - va_list ap) -{ - int size; - va_list copy; - va_copy(copy, ap); - size_t avail = talloc_get_size(s->start) - s->len; - char *dest = s->start ? s->start + s->len : NULL; - char c; - if (avail < 1) - dest = &c; - size = vsnprintf(dest, MPMAX(avail, 1), fmt, copy); - va_end(copy); - - if (size < 0) - abort(); - - if (avail < 1 || size + 1 > avail) { - resize_append(talloc_ctx, s, size + 1); - vsnprintf(s->start + s->len, size + 1, fmt, ap); - } - s->len += size; -} - -bool bstr_case_startswith(struct bstr s, struct bstr prefix) -{ - struct bstr start = bstr_splice(s, 0, prefix.len); - return start.len == prefix.len && bstrcasecmp(start, prefix) == 0; -} - -bool bstr_case_endswith(struct bstr s, struct bstr suffix) -{ - struct bstr end = bstr_cut(s, -suffix.len); - return end.len == suffix.len && bstrcasecmp(end, suffix) == 0; -} - -struct bstr bstr_strip_ext(struct bstr str) -{ - int dotpos = bstrrchr(str, '.'); - if (dotpos < 0) - return str; - return (struct bstr){str.start, dotpos}; -} - -struct bstr bstr_get_ext(struct bstr s) -{ - int dotpos = bstrrchr(s, '.'); - if (dotpos < 0) - return (struct bstr){NULL, 0}; - return bstr_splice(s, dotpos + 1, s.len); -} - -static int h_to_i(unsigned char c) -{ - if (c >= '0' && c <= '9') - return c - '0'; - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - if (c >= 'A' && c <= 'F') - return c - 'A' + 10; - - return -1; // invalid char -} - -bool bstr_decode_hex(void *talloc_ctx, struct bstr hex, struct bstr *out) -{ - if (!out) - return false; - - char *arr = talloc_array(talloc_ctx, char, hex.len / 2); - int len = 0; - - while (hex.len >= 2) { - int a = h_to_i(hex.start[0]); - int b = h_to_i(hex.start[1]); - hex = bstr_splice(hex, 2, hex.len); - - if (a < 0 || b < 0) { - talloc_free(arr); - return false; - } - - arr[len++] = (a << 4) | b; - } - - *out = (struct bstr){ .start = arr, .len = len }; - return true; -} diff --git a/src/mpv/misc/bstr.h b/src/mpv/misc/bstr.h deleted file mode 100644 index 5be35ea..0000000 --- a/src/mpv/misc/bstr.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see . - */ - -#ifndef MPLAYER_BSTR_H -#define MPLAYER_BSTR_H - -#include -#include -#include -#include -#include - -#include "mpv_talloc.h" -#include "osdep/compiler.h" - -/* NOTE: 'len' is size_t, but most string-handling functions below assume - * that input size has been sanity checked and len fits in an int. - */ -typedef struct bstr { - unsigned char *start; - size_t len; -} bstr; - -// If str.start is NULL, return NULL. -static inline char *bstrdup0(void *talloc_ctx, struct bstr str) -{ - return talloc_strndup(talloc_ctx, (char *)str.start, str.len); -} - -// Like bstrdup0(), but always return a valid C-string. -static inline char *bstrto0(void *talloc_ctx, struct bstr str) -{ - return str.start ? bstrdup0(talloc_ctx, str) : talloc_strdup(talloc_ctx, ""); -} - -// Return start = NULL iff that is true for the original. -static inline struct bstr bstrdup(void *talloc_ctx, struct bstr str) -{ - struct bstr r = { NULL, str.len }; - if (str.start) - r.start = (unsigned char *)talloc_memdup(talloc_ctx, str.start, str.len); - return r; -} - -static inline struct bstr bstr0(const char *s) -{ - return (struct bstr){(unsigned char *)s, s ? strlen(s) : 0}; -} - -int bstrcmp(struct bstr str1, struct bstr str2); -int bstrcasecmp(struct bstr str1, struct bstr str2); -int bstrchr(struct bstr str, int c); -int bstrrchr(struct bstr str, int c); -int bstrspn(struct bstr str, const char *accept); -int bstrcspn(struct bstr str, const char *reject); - -int bstr_find(struct bstr haystack, struct bstr needle); -struct bstr bstr_lstrip(struct bstr str); -struct bstr bstr_rstrip(struct bstr str); -struct bstr bstr_strip(struct bstr str); -struct bstr bstr_split(struct bstr str, const char *sep, struct bstr *rest); -bool bstr_split_tok(bstr str, const char *tok, bstr *out_left, bstr *out_right); -struct bstr bstr_splice(struct bstr str, int start, int end); -long long bstrtoll(struct bstr str, struct bstr *rest, int base); -double bstrtod(struct bstr str, struct bstr *rest); -void bstr_lower(struct bstr str); -int bstr_sscanf(struct bstr str, const char *format, ...); - -// Decode a string containing hexadecimal data. All whitespace will be silently -// ignored. When successful, this allocates a new array to store the output. -bool bstr_decode_hex(void *talloc_ctx, struct bstr hex, struct bstr *out); - -// Return the text before the occurrence of a character, and return it. Change -// *rest to point to the text following this character. (rest can be NULL.) -struct bstr bstr_splitchar(struct bstr str, struct bstr *rest, const char c); - -// Like bstr_splitchar. Trailing newlines are not stripped. -static inline struct bstr bstr_getline(struct bstr str, struct bstr *rest) -{ - return bstr_splitchar(str, rest, '\n'); -} - -// Strip one trailing line break. This is intended for use with bstr_getline, -// and will remove the trailing \n or \r\n sequence. -struct bstr bstr_strip_linebreaks(struct bstr str); - -void bstr_xappend(void *talloc_ctx, bstr *s, bstr append); -void bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...) - PRINTF_ATTRIBUTE(3, 4); -void bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va) - PRINTF_ATTRIBUTE(3, 0); - -// If s starts/ends with prefix, return true and return the rest of the string -// in s. -bool bstr_eatstart(struct bstr *s, struct bstr prefix); -bool bstr_eatend(struct bstr *s, struct bstr prefix); - -bool bstr_case_startswith(struct bstr s, struct bstr prefix); -bool bstr_case_endswith(struct bstr s, struct bstr suffix); -struct bstr bstr_strip_ext(struct bstr str); -struct bstr bstr_get_ext(struct bstr s); - -static inline struct bstr bstr_cut(struct bstr str, int n) -{ - if (n < 0) { - n += str.len; - if (n < 0) - n = 0; - } - if (((size_t)n) > str.len) - n = str.len; - return (struct bstr){str.start + n, str.len - n}; -} - -static inline bool bstr_startswith(struct bstr str, struct bstr prefix) -{ - if (str.len < prefix.len) - return false; - return !memcmp(str.start, prefix.start, prefix.len); -} - -static inline bool bstr_startswith0(struct bstr str, const char *prefix) -{ - return bstr_startswith(str, bstr0(prefix)); -} - -static inline bool bstr_endswith(struct bstr str, struct bstr suffix) -{ - if (str.len < suffix.len) - return false; - return !memcmp(str.start + str.len - suffix.len, suffix.start, suffix.len); -} - -static inline bool bstr_endswith0(struct bstr str, const char *suffix) -{ - return bstr_endswith(str, bstr0(suffix)); -} - -static inline int bstrcmp0(struct bstr str1, const char *str2) -{ - return bstrcmp(str1, bstr0(str2)); -} - -static inline bool bstr_equals(struct bstr str1, struct bstr str2) -{ - if (str1.len != str2.len) - return false; - - return str1.start == str2.start || bstrcmp(str1, str2) == 0; -} - -static inline bool bstr_equals0(struct bstr str1, const char *str2) -{ - return bstr_equals(str1, bstr0(str2)); -} - -static inline int bstrcasecmp0(struct bstr str1, const char *str2) -{ - return bstrcasecmp(str1, bstr0(str2)); -} - -static inline int bstr_find0(struct bstr haystack, const char *needle) -{ - return bstr_find(haystack, bstr0(needle)); -} - -static inline bool bstr_eatstart0(struct bstr *s, const char *prefix) -{ - return bstr_eatstart(s, bstr0(prefix)); -} - -static inline bool bstr_eatend0(struct bstr *s, const char *prefix) -{ - return bstr_eatend(s, bstr0(prefix)); -} - -// create a pair (not single value!) for "%.*s" printf syntax -#define BSTR_P(bstr) (int)((bstr).len), ((bstr).start ? (char*)(bstr).start : "") - -#define WHITESPACE " \f\n\r\t\v" - -#endif /* MPLAYER_BSTR_H */ diff --git a/src/mpv/misc/ctype.h b/src/mpv/misc/ctype.h deleted file mode 100644 index cbff799..0000000 --- a/src/mpv/misc/ctype.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef MP_CTYPE_H_ -#define MP_CTYPE_H_ - -// Roughly follows C semantics, but doesn't account for EOF, allows char as -// parameter, and is locale independent (always uses "C" locale). - -static inline int mp_isprint(char c) { return (unsigned char)c >= 32; } -static inline int mp_isspace(char c) { return c == ' ' || c == '\f' || c == '\n' || - c == '\r' || c == '\t' || c =='\v'; } -static inline int mp_isupper(char c) { return c >= 'A' && c <= 'Z'; } -static inline int mp_islower(char c) { return c >= 'a' && c <= 'z'; } -static inline int mp_isdigit(char c) { return c >= '0' && c <= '9'; } -static inline int mp_isalpha(char c) { return mp_isupper(c) || mp_islower(c); } -static inline int mp_isalnum(char c) { return mp_isalpha(c) || mp_isdigit(c); } - -static inline char mp_tolower(char c) { return mp_isupper(c) ? c - 'A' + 'a' : c; } -static inline char mp_toupper(char c) { return mp_islower(c) ? c - 'a' + 'A' : c; } - -#endif