Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-06-30 08:18:03 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-06-30 08:18:03 +0300
commitd59721e47aba4c9db96cfe5b10c63969ff361897 (patch)
tree9158cfdeb118e3b09f19ddc087c71c9ddcfabace
parentd17cb3f75f2c1e3b0d729da24f5fd1793b823760 (diff)
Cleanup: move BLI_char_switch into BLI_string
-rw-r--r--source/blender/blenlib/BLI_path_util.h2
-rw-r--r--source/blender/blenlib/BLI_string.h2
-rw-r--r--source/blender/blenlib/intern/path_util.c38
-rw-r--r--source/blender/blenlib/intern/string.c17
-rw-r--r--source/blender/imbuf/intern/thumbs.c2
5 files changed, 31 insertions, 30 deletions
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index c9a54c33f21..63b5207f941 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -157,8 +157,6 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char
# define BLI_path_ncmp strncmp
#endif
-void BLI_char_switch(char *string, char from, char to) ATTR_NONNULL();
-
#ifdef WITH_ICONV
void BLI_string_to_utf8(char *original, char *utf_8, const char *code);
#endif
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index 4818d717b54..007cb1386ab 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -58,6 +58,8 @@ char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict
char *BLI_str_replaceN(const char *__restrict str, const char *__restrict substr_old, const char *__restrict substr_new) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC;
+void BLI_str_replace_char(char *string, char src, char dst) ATTR_NONNULL();
+
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...) ATTR_NONNULL(1, 3) ATTR_PRINTF_FORMAT(3, 4);
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...) ATTR_NONNULL(1, 3) ATTR_PRINTF_FORMAT(3, 4);
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index b1a7d74e46f..c1f6cc4b49a 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -623,8 +623,8 @@ void BLI_path_rel(char *file, const char *relfile)
BLI_strncpy(temp, relfile, FILE_MAX);
#endif
- BLI_char_switch(temp + BLI_path_unc_prefix_len(temp), '\\', '/');
- BLI_char_switch(file + BLI_path_unc_prefix_len(file), '\\', '/');
+ BLI_str_replace_char(temp + BLI_path_unc_prefix_len(temp), '\\', '/');
+ BLI_str_replace_char(file + BLI_path_unc_prefix_len(file), '\\', '/');
/* remove /./ which confuse the following slash counting... */
BLI_cleanup_path(NULL, file);
@@ -685,7 +685,7 @@ void BLI_path_rel(char *file, const char *relfile)
r += BLI_strcpy_rlen(r, q + 1);
#ifdef WIN32
- BLI_char_switch(res + 2, '/', '\\');
+ BLI_str_replace_char(res + 2, '/', '\\');
#endif
strcpy(file, res);
}
@@ -1032,7 +1032,7 @@ bool BLI_path_abs(char *path, const char *basepath)
* For UNC paths the first characters containing the UNC prefix
* shouldn't be switched as we need to distinguish them from
* paths relative to the .blend file -elubie */
- BLI_char_switch(tmp + BLI_path_unc_prefix_len(tmp), '\\', '/');
+ BLI_str_replace_char(tmp + BLI_path_unc_prefix_len(tmp), '\\', '/');
/* Paths starting with // will get the blend file as their base,
* this isn't standard in any os but is used in blender all over the place */
@@ -1043,7 +1043,7 @@ bool BLI_path_abs(char *path, const char *basepath)
/* file component is ignored, so don't bother with the trailing slash */
BLI_cleanup_path(NULL, base);
lslash = BLI_last_slash(base);
- BLI_char_switch(base + BLI_path_unc_prefix_len(base), '\\', '/');
+ BLI_str_replace_char(base + BLI_path_unc_prefix_len(base), '\\', '/');
if (lslash) {
const int baselen = (int) (lslash - base) + 1; /* length up to and including last "/" */
@@ -1071,7 +1071,7 @@ bool BLI_path_abs(char *path, const char *basepath)
* // will be retained, rest will be nice and
* shiny win32 backward slashes :) -jesterKing
*/
- BLI_char_switch(path + 2, '/', '\\');
+ BLI_str_replace_char(path + 2, '/', '\\');
#endif
/* ensure this is after correcting for path switch */
@@ -1304,22 +1304,6 @@ void BLI_setenv_if_new(const char *env, const char *val)
}
/**
- * Change every \a from in \a string into \a to. The
- * result will be in \a string
- *
- * \param string The string to work on
- * \param from The character to replace
- * \param to The character to replace with
- */
-void BLI_char_switch(char *string, char from, char to)
-{
- while (*string != 0) {
- if (*string == from) *string = to;
- string++;
- }
-}
-
-/**
* Strips off nonexistent (or non-accessible) subdirectories from the end of *dir, leaving the path of
* the lowest-level directory that does exist and we can read.
*/
@@ -1382,9 +1366,9 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c
* any mess with slashes later on. -jesterKing */
/* constant strings can be passed for those parameters - don't change them - elubie */
#if 0
- BLI_char_switch(relabase, '\\', '/');
- BLI_char_switch(dir, '\\', '/');
- BLI_char_switch(file, '\\', '/');
+ BLI_str_replace_char(relabase, '\\', '/');
+ BLI_str_replace_char(dir, '\\', '/');
+ BLI_str_replace_char(file, '\\', '/');
#endif
/* Resolve relative references */
@@ -1911,10 +1895,10 @@ void BLI_path_native_slash(char *path)
{
#ifdef WIN32
if (path && BLI_strnlen(path, 3) > 2) {
- BLI_char_switch(path + 2, '/', '\\');
+ BLI_str_replace_char(path + 2, '/', '\\');
}
#else
- BLI_char_switch(path + BLI_path_unc_prefix_len(path), '\\', '/');
+ BLI_str_replace_char(path + BLI_path_unc_prefix_len(path), '\\', '/');
#endif
}
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 11c1f93ca19..28cc5eb2f9f 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -477,6 +477,23 @@ char *BLI_str_replaceN(const char *__restrict str, const char *__restrict substr
}
/**
+ * In-place replace every \a src to \a dst in \a str.
+ *
+ * \param str: The string to operate on.
+ * \param src: The character to replace.
+ * \param dst: The character to replace with.
+ */
+void BLI_str_replace_char(char *str, char src, char dst)
+{
+ while (*str) {
+ if (*str == src) {
+ *str = dst;
+ }
+ str++;
+ }
+}
+
+/**
* Compare two strings without regard to case.
*
* \retval True if the strings are equal, false otherwise.
diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c
index 7a949b7ffea..4889026dbff 100644
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@ -233,7 +233,7 @@ static int uri_from_filename(const char *path, char *uri)
dirstart += 2;
}
strcat(orig_uri, dirstart);
- BLI_char_switch(orig_uri, '\\', '/');
+ BLI_str_replace_char(orig_uri, '\\', '/');
#else
BLI_snprintf(orig_uri, URI_MAX, "file://%s", dirstart);
#endif