2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
* Copyright 2001-2002 NaN Holding BV. All rights reserved. */
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bli
|
2011-02-27 20:37:56 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-20 12:43:53 +00:00
|
|
|
#include <ctype.h>
|
2018-11-19 15:24:32 +01:00
|
|
|
#include <inttypes.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdarg.h>
|
2021-03-24 16:43:17 +11:00
|
|
|
#include <stdio.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-12-20 10:02:00 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2009-03-25 20:29:01 +00:00
|
|
|
#include "BLI_dynstr.h"
|
2008-12-20 12:43:53 +00:00
|
|
|
#include "BLI_string.h"
|
|
|
|
|
2012-10-31 04:28:49 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2013-05-12 06:33:21 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# pragma GCC diagnostic error "-Wsign-conversion"
|
|
|
|
#endif
|
|
|
|
|
2013-07-15 03:54:57 +00:00
|
|
|
// #define DEBUG_STRSIZE
|
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Duplicate/Copy
|
|
|
|
* \{ */
|
|
|
|
|
2011-09-28 05:53:40 +00:00
|
|
|
char *BLI_strdupn(const char *str, const size_t len)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char *n = MEM_mallocN(len + 1, "strdup");
|
|
|
|
memcpy(n, str, len);
|
|
|
|
n[len] = '\0';
|
2018-06-17 16:32:54 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return n;
|
2008-12-20 10:02:00 +00:00
|
|
|
}
|
2013-03-14 10:07:05 +00:00
|
|
|
|
2011-09-28 05:53:40 +00:00
|
|
|
char *BLI_strdup(const char *str)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_strdupn(str, strlen(str));
|
2008-12-20 10:02:00 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 15:12:13 +00:00
|
|
|
char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2)
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* include the NULL terminator of str2 only */
|
|
|
|
const size_t str1_len = strlen(str1);
|
|
|
|
const size_t str2_len = strlen(str2) + 1;
|
|
|
|
char *str, *s;
|
2018-06-17 16:32:54 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
str = MEM_mallocN(str1_len + str2_len, "strdupcat");
|
|
|
|
s = str;
|
2013-07-23 12:49:30 +00:00
|
|
|
|
2020-08-07 19:19:38 +02:00
|
|
|
memcpy(s, str1, str1_len); /* NOLINT: bugprone-not-null-terminated-result */
|
2019-04-17 06:17:24 +02:00
|
|
|
s += str1_len;
|
|
|
|
memcpy(s, str2, str2_len);
|
2013-07-23 12:49:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return str;
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 15:12:13 +00:00
|
|
|
char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t srclen = BLI_strnlen(src, maxncpy - 1);
|
|
|
|
BLI_assert(maxncpy != 0);
|
2013-03-14 09:49:20 +00:00
|
|
|
|
2013-07-15 03:54:57 +00:00
|
|
|
#ifdef DEBUG_STRSIZE
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(dst, 0xff, sizeof(*dst) * maxncpy);
|
2013-07-15 03:54:57 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
memcpy(dst, src, srclen);
|
|
|
|
dst[srclen] = '\0';
|
|
|
|
return dst;
|
2008-12-20 10:02:00 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
char *BLI_strncpy_ensure_pad(char *__restrict dst,
|
|
|
|
const char *__restrict src,
|
|
|
|
const char pad,
|
|
|
|
size_t maxncpy)
|
2015-01-03 10:13:02 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(maxncpy != 0);
|
2015-01-03 10:13:02 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG_STRSIZE
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(dst, 0xff, sizeof(*dst) * maxncpy);
|
2015-01-03 10:13:02 +01:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (src[0] == '\0') {
|
|
|
|
dst[0] = '\0';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Add heading/trailing wildcards if needed. */
|
|
|
|
size_t idx = 0;
|
|
|
|
size_t srclen;
|
|
|
|
|
|
|
|
if (src[idx] != pad) {
|
|
|
|
dst[idx++] = pad;
|
|
|
|
maxncpy--;
|
|
|
|
}
|
|
|
|
maxncpy--; /* trailing '\0' */
|
|
|
|
|
|
|
|
srclen = BLI_strnlen(src, maxncpy);
|
|
|
|
if ((src[srclen - 1] != pad) && (srclen == maxncpy)) {
|
|
|
|
srclen--;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&dst[idx], src, srclen);
|
|
|
|
idx += srclen;
|
|
|
|
|
|
|
|
if (dst[idx - 1] != pad) {
|
|
|
|
dst[idx++] = pad;
|
|
|
|
}
|
|
|
|
dst[idx] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
2015-01-03 10:13:02 +01:00
|
|
|
}
|
|
|
|
|
2013-03-14 10:07:05 +00:00
|
|
|
size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, const size_t maxncpy)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t srclen = BLI_strnlen(src, maxncpy - 1);
|
|
|
|
BLI_assert(maxncpy != 0);
|
2013-03-14 10:07:05 +00:00
|
|
|
|
2013-07-15 03:54:57 +00:00
|
|
|
#ifdef DEBUG_STRSIZE
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(dst, 0xff, sizeof(*dst) * maxncpy);
|
2013-07-15 03:54:57 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
memcpy(dst, src, srclen);
|
|
|
|
dst[srclen] = '\0';
|
|
|
|
return srclen;
|
2013-03-14 10:07:05 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 08:29:02 +00:00
|
|
|
size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t srclen = strlen(src);
|
|
|
|
memcpy(dst, src, srclen + 1);
|
|
|
|
return srclen;
|
2013-06-16 08:29:02 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Printing
|
|
|
|
* \{ */
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t BLI_vsnprintf(char *__restrict buffer,
|
|
|
|
size_t maxncpy,
|
|
|
|
const char *__restrict format,
|
|
|
|
va_list arg)
|
2008-12-20 10:02:00 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t n;
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(buffer != NULL);
|
|
|
|
BLI_assert(maxncpy > 0);
|
|
|
|
BLI_assert(format != NULL);
|
2012-11-28 06:43:04 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
n = (size_t)vsnprintf(buffer, maxncpy, format, arg);
|
2012-08-26 11:01:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (n != -1 && n < maxncpy) {
|
|
|
|
buffer[n] = '\0';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buffer[maxncpy - 1] = '\0';
|
|
|
|
}
|
2012-08-26 11:01:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return n;
|
2012-08-26 11:01:14 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t BLI_vsnprintf_rlen(char *__restrict buffer,
|
|
|
|
size_t maxncpy,
|
|
|
|
const char *__restrict format,
|
|
|
|
va_list arg)
|
2015-04-22 05:37:22 +10:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t n;
|
2015-04-22 05:37:22 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(buffer != NULL);
|
|
|
|
BLI_assert(maxncpy > 0);
|
|
|
|
BLI_assert(format != NULL);
|
2015-04-22 05:37:22 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
n = (size_t)vsnprintf(buffer, maxncpy, format, arg);
|
2015-04-22 05:37:22 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (n != -1 && n < maxncpy) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
n = maxncpy - 1;
|
|
|
|
}
|
|
|
|
buffer[n] = '\0';
|
2015-04-22 05:37:22 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return n;
|
2015-04-22 05:37:22 +10:00
|
|
|
}
|
|
|
|
|
2013-07-15 03:54:57 +00:00
|
|
|
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...)
|
2012-08-26 11:01:14 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t n;
|
|
|
|
va_list arg;
|
2012-08-26 11:01:14 +00:00
|
|
|
|
2013-07-15 03:54:57 +00:00
|
|
|
#ifdef DEBUG_STRSIZE
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(dst, 0xff, sizeof(*dst) * maxncpy);
|
2013-07-15 03:54:57 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
va_start(arg, format);
|
|
|
|
n = BLI_vsnprintf(dst, maxncpy, format, arg);
|
|
|
|
va_end(arg);
|
2012-08-26 11:01:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return n;
|
2008-12-20 10:02:00 +00:00
|
|
|
}
|
|
|
|
|
2015-04-22 05:37:22 +10:00
|
|
|
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t n;
|
|
|
|
va_list arg;
|
2015-04-22 05:37:22 +10:00
|
|
|
|
|
|
|
#ifdef DEBUG_STRSIZE
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(dst, 0xff, sizeof(*dst) * maxncpy);
|
2015-04-22 05:37:22 +10:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
va_start(arg, format);
|
|
|
|
n = BLI_vsnprintf_rlen(dst, maxncpy, format, arg);
|
|
|
|
va_end(arg);
|
2015-04-22 05:37:22 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return n;
|
2015-04-22 05:37:22 +10:00
|
|
|
}
|
|
|
|
|
2012-11-23 15:12:13 +00:00
|
|
|
char *BLI_sprintfN(const char *__restrict format, ...)
|
2009-03-25 20:29:01 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DynStr *ds;
|
|
|
|
va_list arg;
|
|
|
|
char *n;
|
2009-03-25 20:29:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
va_start(arg, format);
|
2009-03-25 20:29:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ds = BLI_dynstr_new();
|
|
|
|
BLI_dynstr_vappendf(ds, format, arg);
|
|
|
|
n = BLI_dynstr_get_cstring(ds);
|
|
|
|
BLI_dynstr_free(ds);
|
2009-03-25 20:29:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
va_end(arg);
|
2009-03-25 20:29:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return n;
|
2009-03-25 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Escape/Un-Escape
|
|
|
|
* \{ */
|
|
|
|
|
2020-12-10 13:33:55 +11:00
|
|
|
size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy)
|
2011-08-23 15:08:54 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-10 13:33:55 +11:00
|
|
|
BLI_assert(dst_maxncpy != 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-10 13:33:55 +11:00
|
|
|
size_t len = 0;
|
|
|
|
for (; (len < dst_maxncpy) && (*src != '\0'); dst++, src++, len++) {
|
|
|
|
char c = *src;
|
|
|
|
if (ELEM(c, '\\', '"') || /* Use as-is. */
|
|
|
|
((c == '\t') && ((void)(c = 't'), true)) || /* Tab. */
|
|
|
|
((c == '\n') && ((void)(c = 'n'), true)) || /* Newline. */
|
2020-12-10 13:45:57 +11:00
|
|
|
((c == '\r') && ((void)(c = 'r'), true)) || /* Carriage return. */
|
|
|
|
((c == '\a') && ((void)(c = 'a'), true)) || /* Bell. */
|
|
|
|
((c == '\b') && ((void)(c = 'b'), true)) || /* Backspace. */
|
|
|
|
((c == '\f') && ((void)(c = 'f'), true))) /* Form-feed. */
|
2020-12-10 13:33:55 +11:00
|
|
|
{
|
|
|
|
if (UNLIKELY(len + 1 >= dst_maxncpy)) {
|
|
|
|
/* Not enough space to escape. */
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2020-12-10 13:33:55 +11:00
|
|
|
}
|
|
|
|
*dst++ = '\\';
|
|
|
|
len++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2020-12-10 13:33:55 +11:00
|
|
|
*dst = c;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
*dst = '\0';
|
2011-08-28 09:28:41 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return len;
|
2011-08-23 15:08:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 14:22:44 +10:00
|
|
|
BLI_INLINE bool str_unescape_pair(char c_next, char *r_out)
|
|
|
|
{
|
|
|
|
#define CASE_PAIR(value_src, value_dst) \
|
|
|
|
case value_src: { \
|
|
|
|
*r_out = value_dst; \
|
|
|
|
return true; \
|
|
|
|
}
|
|
|
|
switch (c_next) {
|
|
|
|
CASE_PAIR('"', '"'); /* Quote. */
|
|
|
|
CASE_PAIR('\\', '\\'); /* Backslash. */
|
|
|
|
CASE_PAIR('t', '\t'); /* Tab. */
|
|
|
|
CASE_PAIR('n', '\n'); /* Newline. */
|
|
|
|
CASE_PAIR('r', '\r'); /* Carriage return. */
|
|
|
|
CASE_PAIR('a', '\a'); /* Bell. */
|
|
|
|
CASE_PAIR('b', '\b'); /* Backspace. */
|
|
|
|
CASE_PAIR('f', '\f'); /* Form-feed. */
|
|
|
|
}
|
|
|
|
#undef CASE_PAIR
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t BLI_str_unescape_ex(char *__restrict dst,
|
|
|
|
const char *__restrict src,
|
|
|
|
const size_t src_maxncpy,
|
|
|
|
/* Additional arguments to #BLI_str_unescape */
|
|
|
|
const size_t dst_maxncpy,
|
|
|
|
bool *r_is_complete)
|
|
|
|
{
|
|
|
|
size_t len = 0;
|
|
|
|
bool is_complete = true;
|
2022-02-18 16:32:33 +01:00
|
|
|
const size_t max_strlen = dst_maxncpy - 1; /* Account for trailing zero byte. */
|
2021-09-04 14:22:44 +10:00
|
|
|
for (const char *src_end = src + src_maxncpy; (src < src_end) && *src; src++) {
|
2022-02-18 16:32:33 +01:00
|
|
|
if (UNLIKELY(len == max_strlen)) {
|
2021-09-04 14:22:44 +10:00
|
|
|
is_complete = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
char c = *src;
|
|
|
|
if (UNLIKELY(c == '\\') && (str_unescape_pair(*(src + 1), &c))) {
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
dst[len++] = c;
|
|
|
|
}
|
|
|
|
dst[len] = 0;
|
|
|
|
*r_is_complete = is_complete;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2020-12-10 13:42:59 +11:00
|
|
|
size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, const size_t src_maxncpy)
|
|
|
|
{
|
|
|
|
size_t len = 0;
|
2021-09-04 14:22:44 +10:00
|
|
|
for (const char *src_end = src + src_maxncpy; (src < src_end) && *src; src++) {
|
2020-12-10 13:42:59 +11:00
|
|
|
char c = *src;
|
2021-09-04 14:22:44 +10:00
|
|
|
if (UNLIKELY(c == '\\') && (str_unescape_pair(*(src + 1), &c))) {
|
|
|
|
src++;
|
2020-12-10 13:42:59 +11:00
|
|
|
}
|
|
|
|
dst[len++] = c;
|
|
|
|
}
|
|
|
|
dst[len] = 0;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2020-12-10 15:06:16 +11:00
|
|
|
const char *BLI_str_escape_find_quote(const char *str)
|
|
|
|
{
|
|
|
|
bool escape = false;
|
|
|
|
while (*str && (*str != '"' || escape)) {
|
|
|
|
/* A pair of back-slashes represents a single back-slash,
|
|
|
|
* only use a single back-slash for escaping. */
|
|
|
|
escape = (escape == false) && (*str == '\\');
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
return (*str == '"') ? str : NULL;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Quote/Un-Quote
|
|
|
|
* \{ */
|
|
|
|
|
2021-09-01 15:23:58 +10:00
|
|
|
bool BLI_str_quoted_substr_range(const char *__restrict str,
|
|
|
|
const char *__restrict prefix,
|
|
|
|
int *__restrict r_start,
|
|
|
|
int *__restrict r_end)
|
|
|
|
{
|
|
|
|
const char *str_start = strstr(str, prefix);
|
|
|
|
if (str_start == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const size_t prefix_len = strlen(prefix);
|
|
|
|
if (UNLIKELY(prefix_len == 0)) {
|
|
|
|
BLI_assert_msg(0,
|
|
|
|
"Zero length prefix passed in, "
|
|
|
|
"caller must prevent this from happening!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
BLI_assert_msg(prefix[prefix_len - 1] != '"',
|
|
|
|
"Prefix includes trailing quote, "
|
|
|
|
"caller must prevent this from happening!");
|
|
|
|
|
|
|
|
str_start += prefix_len;
|
|
|
|
if (UNLIKELY(*str_start != '\"')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
str_start += 1;
|
|
|
|
const char *str_end = BLI_str_escape_find_quote(str_start);
|
|
|
|
if (UNLIKELY(str_end == NULL)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*r_start = (int)(str_start - str);
|
|
|
|
*r_end = (int)(str_end - str);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-06 15:51:53 +10:00
|
|
|
/* NOTE(@campbellbarton): in principal it should be possible to access a quoted string
|
|
|
|
* with an arbitrary size, currently all callers for this functionality
|
|
|
|
* happened to use a fixed size buffer, so only #BLI_str_quoted_substr is needed. */
|
|
|
|
#if 0
|
2013-03-14 10:07:05 +00:00
|
|
|
/**
|
2021-09-06 15:51:53 +10:00
|
|
|
* Makes a copy of the text within the "" that appear after the contents of \a prefix.
|
2020-12-10 16:01:04 +11:00
|
|
|
* i.e. for string `pose["apples"]` with prefix `pose[`, it will return `apples`.
|
2009-10-12 11:27:34 +00:00
|
|
|
*
|
2020-12-10 16:01:04 +11:00
|
|
|
* \param str: is the entire string to chop.
|
|
|
|
* \param prefix: is the part of the string to step over.
|
2013-03-14 10:07:05 +00:00
|
|
|
*
|
2020-12-10 16:01:04 +11:00
|
|
|
* Assume that the strings returned must be freed afterwards,
|
|
|
|
* and that the inputs will contain data we want.
|
2009-10-12 11:27:34 +00:00
|
|
|
*/
|
2012-11-23 15:12:13 +00:00
|
|
|
char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix)
|
2009-10-12 11:27:34 +00:00
|
|
|
{
|
2021-09-01 15:23:58 +10:00
|
|
|
int start_match_ofs, end_match_ofs;
|
|
|
|
if (!BLI_str_quoted_substr_range(str, prefix, &start_match_ofs, &end_match_ofs)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
const size_t escaped_len = (size_t)(end_match_ofs - start_match_ofs);
|
|
|
|
char *result = MEM_mallocN(sizeof(char) * (escaped_len + 1), __func__);
|
|
|
|
const size_t unescaped_len = BLI_str_unescape(result, str + start_match_ofs, escaped_len);
|
|
|
|
if (unescaped_len != escaped_len) {
|
|
|
|
result = MEM_reallocN(result, sizeof(char) * (unescaped_len + 1));
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2021-09-01 15:23:58 +10:00
|
|
|
return result;
|
2009-10-12 11:27:34 +00:00
|
|
|
}
|
2021-09-06 15:51:53 +10:00
|
|
|
#endif
|
2009-10-12 11:27:34 +00:00
|
|
|
|
2021-09-04 14:22:44 +10:00
|
|
|
bool BLI_str_quoted_substr(const char *__restrict str,
|
|
|
|
const char *__restrict prefix,
|
|
|
|
char *result,
|
|
|
|
size_t result_maxlen)
|
|
|
|
{
|
|
|
|
int start_match_ofs, end_match_ofs;
|
|
|
|
if (!BLI_str_quoted_substr_range(str, prefix, &start_match_ofs, &end_match_ofs)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const size_t escaped_len = (size_t)(end_match_ofs - start_match_ofs);
|
|
|
|
bool is_complete;
|
|
|
|
BLI_str_unescape_ex(result, str + start_match_ofs, escaped_len, result_maxlen, &is_complete);
|
|
|
|
if (is_complete == false) {
|
|
|
|
*result = '\0';
|
|
|
|
}
|
|
|
|
return is_complete;
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Replace
|
|
|
|
* \{ */
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
char *BLI_str_replaceN(const char *__restrict str,
|
|
|
|
const char *__restrict substr_old,
|
|
|
|
const char *__restrict substr_new)
|
2009-10-09 12:18:32 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DynStr *ds = NULL;
|
|
|
|
size_t len_old = strlen(substr_old);
|
|
|
|
const char *match;
|
|
|
|
|
|
|
|
BLI_assert(substr_old[0] != '\0');
|
|
|
|
|
2020-07-02 12:58:25 +10:00
|
|
|
/* While we can still find a match for the old sub-string that we're searching for,
|
|
|
|
* keep dicing and replacing. */
|
2019-04-17 06:17:24 +02:00
|
|
|
while ((match = strstr(str, substr_old))) {
|
|
|
|
/* the assembly buffer only gets created when we actually need to rebuild the string */
|
|
|
|
if (ds == NULL) {
|
|
|
|
ds = BLI_dynstr_new();
|
|
|
|
}
|
|
|
|
|
2020-07-02 12:58:25 +10:00
|
|
|
/* If the match position does not match the current position in the string,
|
|
|
|
* copy the text up to this position and advance the current position in the string. */
|
2019-04-17 06:17:24 +02:00
|
|
|
if (str != match) {
|
2020-07-02 12:58:25 +10:00
|
|
|
/* Add the segment of the string from `str` to match to the buffer,
|
|
|
|
* then restore the value at match. */
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_nappend(ds, str, (match - str));
|
|
|
|
|
|
|
|
/* now our current position should be set on the start of the match */
|
|
|
|
str = match;
|
|
|
|
}
|
|
|
|
|
2020-07-02 12:58:25 +10:00
|
|
|
/* Add the replacement text to the accumulation buffer. */
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, substr_new);
|
|
|
|
|
2020-07-02 12:58:25 +10:00
|
|
|
/* Advance the current position of the string up to the end of the replaced segment. */
|
2019-04-17 06:17:24 +02:00
|
|
|
str += len_old;
|
|
|
|
}
|
|
|
|
|
2020-07-02 12:58:25 +10:00
|
|
|
/* Finish off and return a new string that has had all occurrences of. */
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ds) {
|
|
|
|
char *str_new;
|
|
|
|
|
2020-07-02 12:58:25 +10:00
|
|
|
/* Add what's left of the string to the assembly buffer
|
|
|
|
* - we've been adjusting `str` to point at the end of the replaced segments. */
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_dynstr_append(ds, str);
|
|
|
|
|
2020-07-02 12:58:25 +10:00
|
|
|
/* Convert to new c-string (MEM_malloc'd), and free the buffer. */
|
2019-04-17 06:17:24 +02:00
|
|
|
str_new = BLI_dynstr_get_cstring(ds);
|
|
|
|
BLI_dynstr_free(ds);
|
|
|
|
|
|
|
|
return str_new;
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
/* Just create a new copy of the entire string - we avoid going through the assembly buffer
|
|
|
|
* for what should be a bit more efficiency. */
|
|
|
|
return BLI_strdup(str);
|
2018-06-17 16:32:54 +02:00
|
|
|
}
|
2009-10-09 12:18:32 +00:00
|
|
|
|
2015-06-30 15:18:03 +10:00
|
|
|
void BLI_str_replace_char(char *str, char src, char dst)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
while (*str) {
|
|
|
|
if (*str == src) {
|
|
|
|
*str = dst;
|
|
|
|
}
|
|
|
|
str++;
|
|
|
|
}
|
2015-06-30 15:18:03 +10:00
|
|
|
}
|
|
|
|
|
2021-04-21 17:34:18 +10:00
|
|
|
bool BLI_str_replace_table_exact(char *string,
|
|
|
|
const size_t string_len,
|
|
|
|
const char *replace_table[][2],
|
|
|
|
int replace_table_len)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < replace_table_len; i++) {
|
|
|
|
if (STREQ(string, replace_table[i][0])) {
|
|
|
|
BLI_strncpy(string, replace_table[i][1], string_len);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Comparison/Matching
|
|
|
|
* \{ */
|
|
|
|
|
2018-06-17 16:32:54 +02:00
|
|
|
int BLI_strcaseeq(const char *a, const char *b)
|
2.5
More cleanup!
- removed old UI font completely, including from uiBeginBlock
- emboss hints for uiBlock only have three types now;
Regular, Pulldown, or "Nothing" (only icon/text)
- removed old font path from Userdef
- removed all old button theme hinting
- removed old "auto block" to merge buttons in groups
(was only in use for radiosity buttons)
And went over all warnings. One hooray for make giving clean output :)
Well, we need uniform definitions for warnings, so people at least fix
them... here's the real bad bugs I found:
- in mesh code, a call to editmesh mixed *em and *me
- in armature, ED_util.h was not included, so no warnings for wrong call
to ED_undo_push()
- The extern Py api .h was not included in the bpy_interface.c, showing
a several calls using different args.
Further just added the missing includes, and removed unused vars.
2009-04-14 15:59:52 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (BLI_strcasecmp(a, b) == 0);
|
2008-12-20 10:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *BLI_strcasestr(const char *s, const char *find)
|
|
|
|
{
|
2020-02-20 11:18:29 +11:00
|
|
|
char c, sc;
|
|
|
|
size_t len;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if ((c = *find++) != 0) {
|
|
|
|
c = tolower(c);
|
|
|
|
len = strlen(find);
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
if ((sc = *s++) == 0) {
|
2020-08-08 11:02:11 +10:00
|
|
|
return NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
sc = tolower(sc);
|
|
|
|
} while (sc != c);
|
|
|
|
} while (BLI_strncasecmp(s, find, len) != 0);
|
|
|
|
s--;
|
|
|
|
}
|
|
|
|
return ((char *)s);
|
2008-12-20 10:02:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 10:08:42 +02:00
|
|
|
int BLI_string_max_possible_word_count(const int str_len)
|
|
|
|
{
|
|
|
|
return (str_len / 2) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BLI_string_has_word_prefix(const char *haystack, const char *needle, size_t needle_len)
|
|
|
|
{
|
|
|
|
const char *match = BLI_strncasestr(haystack, needle, needle_len);
|
|
|
|
if (match) {
|
|
|
|
if ((match == haystack) || (*(match - 1) == ' ') || ispunct(*(match - 1))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return BLI_string_has_word_prefix(match + 1, needle, needle_len);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BLI_string_all_words_matched(const char *name,
|
|
|
|
const char *str,
|
|
|
|
int (*words)[2],
|
|
|
|
const int words_len)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
for (index = 0; index < words_len; index++) {
|
|
|
|
if (!BLI_string_has_word_prefix(name, str + words[index][0], (size_t)words[index][1])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const bool all_words_matched = (index == words_len);
|
|
|
|
|
|
|
|
return all_words_matched;
|
|
|
|
}
|
|
|
|
|
2016-03-23 18:45:32 +11:00
|
|
|
char *BLI_strncasestr(const char *s, const char *find, size_t len)
|
|
|
|
{
|
2020-02-20 11:18:29 +11:00
|
|
|
char c, sc;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if ((c = *find++) != 0) {
|
|
|
|
c = tolower(c);
|
|
|
|
if (len > 1) {
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
if ((sc = *s++) == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sc = tolower(sc);
|
|
|
|
} while (sc != c);
|
|
|
|
} while (BLI_strncasecmp(s, find, len - 1) != 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
if ((sc = *s++) == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
sc = tolower(sc);
|
|
|
|
} while (sc != c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s--;
|
|
|
|
}
|
|
|
|
return ((char *)s);
|
2016-03-23 18:45:32 +11:00
|
|
|
}
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2011-09-28 05:53:40 +00:00
|
|
|
int BLI_strcasecmp(const char *s1, const char *s2)
|
|
|
|
{
|
2020-02-20 11:18:29 +11:00
|
|
|
int i;
|
|
|
|
char c1, c2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
for (i = 0;; i++) {
|
|
|
|
c1 = tolower(s1[i]);
|
|
|
|
c2 = tolower(s2[i]);
|
|
|
|
|
|
|
|
if (c1 < c2) {
|
|
|
|
return -1;
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (c1 > c2) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (c1 == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-12-20 10:02:00 +00:00
|
|
|
}
|
|
|
|
|
2011-09-28 05:53:40 +00:00
|
|
|
int BLI_strncasecmp(const char *s1, const char *s2, size_t len)
|
|
|
|
{
|
2020-02-20 11:18:29 +11:00
|
|
|
size_t i;
|
|
|
|
char c1, c2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
c1 = tolower(s1[i]);
|
|
|
|
c2 = tolower(s2[i]);
|
|
|
|
|
|
|
|
if (c1 < c2) {
|
|
|
|
return -1;
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (c1 > c2) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (c1 == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-12-20 10:02:00 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 14:52:23 +00:00
|
|
|
/* compare number on the left size of the string */
|
|
|
|
static int left_number_strcmp(const char *s1, const char *s2, int *tiebreaker)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *p1 = s1, *p2 = s2;
|
|
|
|
int numdigit, numzero1, numzero2;
|
|
|
|
|
|
|
|
/* count and skip leading zeros */
|
|
|
|
for (numzero1 = 0; *p1 == '0'; numzero1++) {
|
|
|
|
p1++;
|
|
|
|
}
|
|
|
|
for (numzero2 = 0; *p2 == '0'; numzero2++) {
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find number of consecutive digits */
|
|
|
|
for (numdigit = 0;; numdigit++) {
|
|
|
|
if (isdigit(*(p1 + numdigit)) && isdigit(*(p2 + numdigit))) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (isdigit(*(p1 + numdigit))) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1; /* s2 is bigger */
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (isdigit(*(p2 + numdigit))) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return -1; /* s1 is bigger */
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* same number of digits, compare size of number */
|
|
|
|
if (numdigit > 0) {
|
|
|
|
int compare = (int)strncmp(p1, p2, (size_t)numdigit);
|
|
|
|
|
|
|
|
if (compare != 0) {
|
|
|
|
return compare;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use number of leading zeros as tie breaker if still equal */
|
|
|
|
if (*tiebreaker == 0) {
|
|
|
|
if (numzero1 > numzero2) {
|
|
|
|
*tiebreaker = 1;
|
|
|
|
}
|
|
|
|
else if (numzero1 < numzero2) {
|
|
|
|
*tiebreaker = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-05-10 14:52:23 +00:00
|
|
|
}
|
|
|
|
|
2019-08-31 17:28:48 +10:00
|
|
|
int BLI_strcasecmp_natural(const char *s1, const char *s2)
|
2009-06-08 20:08:19 +00:00
|
|
|
{
|
2020-02-20 11:18:29 +11:00
|
|
|
int d1 = 0, d2 = 0;
|
|
|
|
char c1, c2;
|
2019-04-17 06:17:24 +02:00
|
|
|
int tiebreaker = 0;
|
|
|
|
|
|
|
|
/* if both chars are numeric, to a left_number_strcmp().
|
|
|
|
* then increase string deltas as long they are
|
|
|
|
* numeric, else do a tolower and char compare */
|
|
|
|
|
|
|
|
while (1) {
|
2019-08-31 02:40:34 +10:00
|
|
|
if (isdigit(s1[d1]) && isdigit(s2[d2])) {
|
2019-04-17 06:17:24 +02:00
|
|
|
int numcompare = left_number_strcmp(s1 + d1, s2 + d2, &tiebreaker);
|
|
|
|
|
|
|
|
if (numcompare != 0) {
|
|
|
|
return numcompare;
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:04:00 +01:00
|
|
|
/* Some wasted work here, left_number_strcmp already consumes at least some digits. */
|
2019-04-17 06:17:24 +02:00
|
|
|
d1++;
|
|
|
|
while (isdigit(s1[d1])) {
|
|
|
|
d1++;
|
|
|
|
}
|
|
|
|
d2++;
|
|
|
|
while (isdigit(s2[d2])) {
|
|
|
|
d2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:04:00 +01:00
|
|
|
/* Test for end of strings first so that shorter strings are ordered in front. */
|
|
|
|
if (ELEM(0, s1[d1], s2[d2])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-31 02:40:34 +10:00
|
|
|
c1 = tolower(s1[d1]);
|
|
|
|
c2 = tolower(s2[d2]);
|
|
|
|
|
2020-01-08 16:04:00 +01:00
|
|
|
if (c1 == c2) {
|
|
|
|
/* Continue iteration */
|
|
|
|
}
|
|
|
|
/* Check for '.' so "foo.bar" comes before "foo 1.bar". */
|
|
|
|
else if (c1 == '.') {
|
2019-04-17 06:17:24 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2020-01-08 16:04:00 +01:00
|
|
|
else if (c2 == '.') {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (c1 < c2) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (c1 > c2) {
|
|
|
|
return 1;
|
|
|
|
}
|
2020-01-08 16:04:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
d1++;
|
|
|
|
d2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tiebreaker) {
|
|
|
|
return tiebreaker;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we might still have a different string because of lower/upper case, in
|
|
|
|
* that case fall back to regular string comparison */
|
|
|
|
return strcmp(s1, s2);
|
2009-06-08 20:08:19 +00:00
|
|
|
}
|
|
|
|
|
2015-01-03 10:13:02 +01:00
|
|
|
int BLI_strcmp_ignore_pad(const char *str1, const char *str2, const char pad)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t str1_len, str2_len;
|
|
|
|
|
|
|
|
while (*str1 == pad) {
|
|
|
|
str1++;
|
|
|
|
}
|
|
|
|
while (*str2 == pad) {
|
|
|
|
str2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
str1_len = strlen(str1);
|
|
|
|
str2_len = strlen(str2);
|
|
|
|
|
|
|
|
while (str1_len && (str1[str1_len - 1] == pad)) {
|
|
|
|
str1_len--;
|
|
|
|
}
|
|
|
|
while (str2_len && (str2[str2_len - 1] == pad)) {
|
|
|
|
str2_len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str1_len == str2_len) {
|
|
|
|
return strncmp(str1, str2, str2_len);
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
if (str1_len > str2_len) {
|
2019-04-17 06:17:24 +02:00
|
|
|
int ret = strncmp(str1, str2, str2_len);
|
|
|
|
if (ret == 0) {
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2020-08-07 11:23:02 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int ret = strncmp(str1, str2, str1_len);
|
|
|
|
if (ret == 0) {
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2015-01-03 10:13:02 +01:00
|
|
|
}
|
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Comparison at Start/End
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
int BLI_str_index_in_array_n(const char *__restrict str,
|
|
|
|
const char **__restrict str_array,
|
|
|
|
const int str_array_len)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
const char **str_iter = str_array;
|
|
|
|
|
|
|
|
for (index = 0; index < str_array_len; str_iter++, index++) {
|
|
|
|
if (STREQ(str, *str_iter)) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BLI_str_index_in_array(const char *__restrict str, const char **__restrict str_array)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
const char **str_iter = str_array;
|
|
|
|
|
|
|
|
for (index = 0; *str_iter; str_iter++, index++) {
|
|
|
|
if (STREQ(str, *str_iter)) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BLI_str_startswith(const char *__restrict str, const char *__restrict start)
|
|
|
|
{
|
|
|
|
for (; *str && *start; str++, start++) {
|
|
|
|
if (*str != *start) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*start == '\0');
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, size_t slength)
|
|
|
|
{
|
|
|
|
size_t elength = strlen(end);
|
|
|
|
|
|
|
|
if (elength < slength) {
|
|
|
|
const char *iter = &str[slength - elength];
|
|
|
|
while (*iter) {
|
|
|
|
if (*iter++ != *end++) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BLI_str_endswith(const char *__restrict str, const char *__restrict end)
|
|
|
|
{
|
|
|
|
const size_t slength = strlen(str);
|
|
|
|
return BLI_strn_endswith(str, end, slength);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Length
|
|
|
|
* \{ */
|
|
|
|
|
2013-06-21 12:33:19 +00:00
|
|
|
size_t BLI_strnlen(const char *s, const size_t maxlen)
|
2010-05-08 15:37:29 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
for (len = 0; len < maxlen; len++, s++) {
|
|
|
|
if (!*s) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
2010-05-08 15:37:29 +00:00
|
|
|
}
|
2010-08-28 12:34:22 +00:00
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Case Conversion
|
|
|
|
* \{ */
|
|
|
|
|
2015-07-14 09:17:00 +10:00
|
|
|
void BLI_str_tolower_ascii(char *str, const size_t len)
|
2011-05-26 09:58:22 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t i;
|
2011-05-26 09:58:22 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (i = 0; (i < len) && str[i]; i++) {
|
|
|
|
if (str[i] >= 'A' && str[i] <= 'Z') {
|
|
|
|
str[i] += 'a' - 'A';
|
|
|
|
}
|
|
|
|
}
|
2011-05-26 09:58:22 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 09:17:00 +10:00
|
|
|
void BLI_str_toupper_ascii(char *str, const size_t len)
|
2011-05-26 09:58:22 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t i;
|
2011-05-26 09:58:22 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (i = 0; (i < len) && str[i]; i++) {
|
|
|
|
if (str[i] >= 'a' && str[i] <= 'z') {
|
|
|
|
str[i] -= 'a' - 'A';
|
|
|
|
}
|
|
|
|
}
|
2011-05-26 09:58:22 +00:00
|
|
|
}
|
2013-03-04 04:21:51 +00:00
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Stripping
|
|
|
|
* \{ */
|
|
|
|
|
2018-08-15 14:47:48 +02:00
|
|
|
void BLI_str_rstrip(char *str)
|
|
|
|
{
|
2020-02-28 11:46:52 +11:00
|
|
|
for (int i = (int)strlen(str) - 1; i >= 0; i--) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (isspace(str[i])) {
|
|
|
|
str[i] = '\0';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-08-15 14:47:48 +02:00
|
|
|
}
|
|
|
|
|
2013-03-04 04:21:51 +00:00
|
|
|
int BLI_str_rstrip_float_zero(char *str, const char pad)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char *p = strchr(str, '.');
|
|
|
|
int totstrip = 0;
|
|
|
|
if (p) {
|
|
|
|
char *end_p;
|
|
|
|
p++; /* position at first decimal place */
|
|
|
|
end_p = p + (strlen(p) - 1); /* position at last character */
|
|
|
|
if (end_p > p) {
|
|
|
|
while (end_p != p && *end_p == '0') {
|
|
|
|
*end_p = pad;
|
|
|
|
end_p--;
|
|
|
|
totstrip++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return totstrip;
|
2013-03-04 04:21:51 +00:00
|
|
|
}
|
2014-06-17 15:58:07 +02:00
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|
2015-01-07 22:25:33 +01:00
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Split (Partition)
|
|
|
|
* \{ */
|
2015-01-07 22:25:33 +01:00
|
|
|
|
2015-06-27 11:00:47 +02:00
|
|
|
size_t BLI_str_partition(const char *str, const char delim[], const char **sep, const char **suf)
|
2014-07-04 14:14:06 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_str_partition_ex(str, NULL, delim, sep, suf, false);
|
2014-07-04 14:14:06 +02:00
|
|
|
}
|
|
|
|
|
2015-06-27 11:00:47 +02:00
|
|
|
size_t BLI_str_rpartition(const char *str, const char delim[], const char **sep, const char **suf)
|
2014-07-04 14:14:06 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_str_partition_ex(str, NULL, delim, sep, suf, true);
|
2014-07-04 14:14:06 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
size_t BLI_str_partition_ex(const char *str,
|
|
|
|
const char *end,
|
|
|
|
const char delim[],
|
|
|
|
const char **sep,
|
|
|
|
const char **suf,
|
|
|
|
const bool from_right)
|
2014-07-04 14:14:06 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *d;
|
|
|
|
char *(*func)(const char *str, int c) = from_right ? strrchr : strchr;
|
|
|
|
|
|
|
|
BLI_assert(end == NULL || end > str);
|
|
|
|
|
|
|
|
*sep = *suf = NULL;
|
|
|
|
|
2019-09-08 00:12:26 +10:00
|
|
|
for (d = delim; *d != '\0'; d++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (end) {
|
|
|
|
if (from_right) {
|
|
|
|
for (tmp = end - 1; (tmp >= str) && (*tmp != *d); tmp--) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
if (tmp < str) {
|
|
|
|
tmp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmp = func(str, *d);
|
|
|
|
if (tmp >= end) {
|
|
|
|
tmp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmp = func(str, *d);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp && (from_right ? (*sep < tmp) : (!*sep || *sep > tmp))) {
|
|
|
|
*sep = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*sep) {
|
|
|
|
*suf = *sep + 1;
|
|
|
|
return (size_t)(*sep - str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return end ? (size_t)(end - str) : strlen(str);
|
2014-07-04 14:14:06 +02:00
|
|
|
}
|
2014-07-17 14:54:12 +10:00
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
int BLI_string_find_split_words(
|
|
|
|
const char *str, const size_t len, const char delim, int r_words[][2], int words_max)
|
|
|
|
{
|
|
|
|
int n = 0, i;
|
|
|
|
bool charsearch = true;
|
|
|
|
|
|
|
|
/* Skip leading spaces */
|
|
|
|
for (i = 0; (i < len) && (str[i] != '\0'); i++) {
|
|
|
|
if (str[i] != delim) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; (i < len) && (str[i] != '\0') && (n < words_max); i++) {
|
|
|
|
if ((str[i] != delim) && (charsearch == true)) {
|
|
|
|
r_words[n][0] = i;
|
|
|
|
charsearch = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((str[i] == delim) && (charsearch == false)) {
|
|
|
|
r_words[n][1] = i - r_words[n][0];
|
|
|
|
n++;
|
|
|
|
charsearch = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (charsearch == false) {
|
|
|
|
r_words[n][1] = i - r_words[n][0];
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name String Formatting (Numeric)
|
|
|
|
* \{ */
|
|
|
|
|
2018-11-22 05:25:51 +11:00
|
|
|
static size_t BLI_str_format_int_grouped_ex(char src[16], char dst[16], int num_len)
|
2014-07-17 14:54:12 +10:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char *p_src = src;
|
|
|
|
char *p_dst = dst;
|
|
|
|
|
|
|
|
const char separator = ',';
|
|
|
|
int commas;
|
|
|
|
|
|
|
|
if (*p_src == '-') {
|
|
|
|
*p_dst++ = *p_src++;
|
|
|
|
num_len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (commas = 2 - num_len % 3; *p_src; commas = (commas + 1) % 3) {
|
|
|
|
*p_dst++ = *p_src++;
|
|
|
|
if (commas == 1) {
|
|
|
|
*p_dst++ = separator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*--p_dst = '\0';
|
|
|
|
|
|
|
|
return (size_t)(p_dst - dst);
|
2014-07-17 14:54:12 +10:00
|
|
|
}
|
2016-03-23 18:45:32 +11:00
|
|
|
|
2018-11-19 15:24:32 +01:00
|
|
|
size_t BLI_str_format_int_grouped(char dst[16], int num)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char src[16];
|
|
|
|
int num_len = sprintf(src, "%d", num);
|
2018-11-19 15:24:32 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_str_format_int_grouped_ex(src, dst, num_len);
|
2018-11-19 15:24:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t BLI_str_format_uint64_grouped(char dst[16], uint64_t num)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* NOTE: Buffer to hold maximum unsigned int64, which is 1.8e+19. but
|
|
|
|
* we also need space for commas and null-terminator. */
|
|
|
|
char src[27];
|
|
|
|
int num_len = sprintf(src, "%" PRIu64 "", num);
|
2018-11-19 15:24:32 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_str_format_int_grouped_ex(src, dst, num_len);
|
2018-11-19 15:24:32 +01:00
|
|
|
}
|
|
|
|
|
2018-05-25 22:17:15 +02:00
|
|
|
void BLI_str_format_byte_unit(char dst[15], long long int bytes, const bool base_10)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
double bytes_converted = bytes;
|
|
|
|
int order = 0;
|
|
|
|
int decimals;
|
|
|
|
const int base = base_10 ? 1000 : 1024;
|
|
|
|
const char *units_base_10[] = {"B", "KB", "MB", "GB", "TB", "PB"};
|
|
|
|
const char *units_base_2[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB"};
|
|
|
|
const int tot_units = ARRAY_SIZE(units_base_2);
|
|
|
|
|
|
|
|
BLI_STATIC_ASSERT(ARRAY_SIZE(units_base_2) == ARRAY_SIZE(units_base_10), "array size mismatch");
|
|
|
|
|
2020-03-06 17:18:10 +01:00
|
|
|
while ((fabs(bytes_converted) >= base) && ((order + 1) < tot_units)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bytes_converted /= base;
|
|
|
|
order++;
|
|
|
|
}
|
|
|
|
decimals = MAX2(order - 1, 0);
|
|
|
|
|
|
|
|
/* Format value first, stripping away floating zeroes. */
|
|
|
|
const size_t dst_len = 15;
|
|
|
|
size_t len = BLI_snprintf_rlen(dst, dst_len, "%.*f", decimals, bytes_converted);
|
|
|
|
len -= (size_t)BLI_str_rstrip_float_zero(dst, '\0');
|
|
|
|
dst[len++] = ' ';
|
|
|
|
BLI_strncpy(dst + len, base_10 ? units_base_10[order] : units_base_2[order], dst_len - len);
|
2018-05-25 22:17:15 +02:00
|
|
|
}
|
|
|
|
|
2021-06-25 07:57:24 +02:00
|
|
|
void BLI_str_format_attribute_domain_size(char dst[7], int number_to_format)
|
|
|
|
{
|
|
|
|
float number_to_format_converted = number_to_format;
|
|
|
|
int order = 0;
|
|
|
|
const float base = 1000;
|
|
|
|
const char *units[] = {"", "K", "M", "B"};
|
|
|
|
const int tot_units = ARRAY_SIZE(units);
|
|
|
|
|
|
|
|
while ((fabsf(number_to_format_converted) >= base) && ((order + 1) < tot_units)) {
|
|
|
|
number_to_format_converted /= base;
|
|
|
|
order++;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t dst_len = 7;
|
|
|
|
int decimals = 0;
|
|
|
|
if ((order > 0) && fabsf(number_to_format_converted) < 100.0f) {
|
|
|
|
decimals = 1;
|
|
|
|
}
|
|
|
|
BLI_snprintf(dst, dst_len, "%.*f%s", decimals, number_to_format_converted, units[order]);
|
|
|
|
}
|
|
|
|
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \} */
|