mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2025-02-18 14:28:31 +00:00
* FBT: cdefines to env, libs order * API: strtod, modf, itoa, calloc * Apps: elk js * Apps: mjs * JS: scripts as assets * mjs: composite resolver * mjs: stack trace * ELK JS example removed * MJS thread, MJS lib modified to support script interruption * JS console UI * Module system, BadUSB bindings rework * JS notifications, simple dialog, BadUSB demo * Custom dialogs, dialog demo * MJS as system library, some dirty hacks to make it compile * Plugin-based js modules * js_uart(BadUART) module * js_uart: support for byte array arguments * Script icon and various fixes * File browser: multiple extensions filter, running js scripts from app loader * Running js scripts from archive browser * JS Runner as system app * Example scripts moved to /ext/apps/Scripts * JS bytecode listing generation * MJS builtin printf cleanup * JS examples cleanup * mbedtls version fix * Unused lib cleanup * Making PVS happy & TODOs cleanup * TODOs cleanup #2 * MJS: initial typed arrays support * JS: fix mem leak in uart destructor Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
113 lines
3 KiB
C
113 lines
3 KiB
C
/*
|
|
* Copyright (c) 2014-2018 Cesanta Software Limited
|
|
* All rights reserved
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the ""License"");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an ""AS IS"" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#ifndef CS_COMMON_MG_STR_H_
|
|
#define CS_COMMON_MG_STR_H_
|
|
|
|
#include <stddef.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Describes chunk of memory */
|
|
struct mg_str {
|
|
const char *p; /* Memory chunk pointer */
|
|
size_t len; /* Memory chunk length */
|
|
};
|
|
|
|
/*
|
|
* Helper function for creating mg_str struct from plain C string.
|
|
* `NULL` is allowed and becomes `{NULL, 0}`.
|
|
*/
|
|
struct mg_str mg_mk_str(const char *s);
|
|
|
|
/*
|
|
* Like `mg_mk_str`, but takes string length explicitly.
|
|
*/
|
|
struct mg_str mg_mk_str_n(const char *s, size_t len);
|
|
|
|
/* Macro for initializing mg_str. */
|
|
#define MG_MK_STR(str_literal) \
|
|
{ str_literal, sizeof(str_literal) - 1 }
|
|
#define MG_MK_STR_N(str_literal, len) \
|
|
{ str_literal, len }
|
|
#define MG_NULL_STR \
|
|
{ NULL, 0 }
|
|
|
|
/*
|
|
* Cross-platform version of `strcmp()` where where first string is
|
|
* specified by `struct mg_str`.
|
|
*/
|
|
int mg_vcmp(const struct mg_str *str2, const char *str1);
|
|
|
|
/*
|
|
* Cross-platform version of `strncasecmp()` where first string is
|
|
* specified by `struct mg_str`.
|
|
*/
|
|
int mg_vcasecmp(const struct mg_str *str2, const char *str1);
|
|
|
|
/* Creates a copy of s (heap-allocated). */
|
|
struct mg_str mg_strdup(const struct mg_str s);
|
|
|
|
/*
|
|
* Creates a copy of s (heap-allocated).
|
|
* Resulting string is NUL-terminated (but NUL is not included in len).
|
|
*/
|
|
struct mg_str mg_strdup_nul(const struct mg_str s);
|
|
|
|
/*
|
|
* Locates character in a string.
|
|
*/
|
|
const char *mg_strchr(const struct mg_str s, int c);
|
|
|
|
/*
|
|
* Compare two `mg_str`s; return value is the same as `strcmp`.
|
|
*/
|
|
int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
|
|
|
|
/*
|
|
* Like `mg_strcmp`, but compares at most `n` characters.
|
|
*/
|
|
int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n);
|
|
|
|
/*
|
|
* Compare two `mg_str`s ignoreing case; return value is the same as `strcmp`.
|
|
*/
|
|
int mg_strcasecmp(const struct mg_str str1, const struct mg_str str2);
|
|
|
|
/*
|
|
* Free the string (assuming it was heap allocated).
|
|
*/
|
|
void mg_strfree(struct mg_str *s);
|
|
|
|
/*
|
|
* Finds the first occurrence of a substring `needle` in the `haystack`.
|
|
*/
|
|
const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);
|
|
|
|
/* Strip whitespace at the start and the end of s */
|
|
struct mg_str mg_strstrip(struct mg_str s);
|
|
|
|
/* Returns 1 if s starts with the given prefix. */
|
|
int mg_str_starts_with(struct mg_str s, struct mg_str prefix);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* CS_COMMON_MG_STR_H_ */
|