summaryrefslogtreecommitdiff
path: root/src/path.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-10-02 12:06:26 -0700
committerRussell Belfer <rb@github.com>2013-10-03 10:44:13 -0700
commit618b7689e1cdd4ebd956949a95038fd49592a187 (patch)
tree6b1aee028a047fa12c6720758379052f69fc6db0 /src/path.h
parentd0849f830f494445e4ef9f04d32be1a2d10b89b3 (diff)
downloadlibgit2-618b7689e1cdd4ebd956949a95038fd49592a187.tar.gz
Wrap iconv stuff and write tests
This adds a simple wrapper around the iconv APIs and uses it instead of the old code that was inlining the iconv stuff. This makes it possible for me to test the iconv logic in isolation. A "no iconv" version of the API was defined with macros so that I could have fewer ifdefs in the code itself.
Diffstat (limited to 'src/path.h')
-rw-r--r--src/path.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/path.h b/src/path.h
index 534cfe50b..2cfd714cd 100644
--- a/src/path.h
+++ b/src/path.h
@@ -358,4 +358,56 @@ extern int git_path_dirload_with_stat(
const char *end_stat,
git_vector *contents);
+/* check if non-ascii characters are present in filename */
+extern bool git_path_has_non_ascii(const char *path, size_t pathlen);
+
+/* only enable iconv on Mac for now */
+#ifdef __APPLE__
+#define GIT_USE_ICONV 1
+#endif
+
+#define GIT_PATH_REPO_ENCODING "UTF-8"
+
+#ifdef __APPLE__
+#define GIT_PATH_NATIVE_ENCODING "UTF-8-MAC"
+#else
+#define GIT_PATH_NATIVE_ENCODING "UTF-8"
+#endif
+
+#ifdef GIT_USE_ICONV
+
+#include <iconv.h>
+
+typedef struct {
+ iconv_t map;
+ git_buf buf;
+} git_path_iconv_t;
+
+#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_BUF_INIT }
+
+/* Init iconv data for converting decomposed UTF-8 to precomposed */
+extern int git_path_iconv_init_precompose(git_path_iconv_t *ic);
+
+/* Clear allocated iconv data */
+extern void git_path_iconv_clear(git_path_iconv_t *ic);
+
+/*
+ * Rewrite `in` buffer using iconv map if necessary, replacing `in`
+ * pointer internal iconv buffer if rewrite happened. The `in` pointer
+ * will be left unchanged if no rewrite was needed.
+ */
+extern int git_path_iconv(git_path_iconv_t *ic, char **in, size_t *inlen);
+
+#else
+
+typedef struct {
+ int unused;
+} git_path_iconv_t;
+#define GIT_PATH_ICONV_INIT { 0 }
+#define git_path_iconv_init_precompose(X) 0
+#define git_path_iconv_clear(X) (void)(X)
+#define git_path_iconv(X,Y,Z) 0
+
+#endif /* GIT_USE_ICONV */
+
#endif