Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_subr/utf8proc/utf8proc_internal.h URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_subr/utf8proc/utf8proc_internal.h?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_subr/utf8proc/utf8proc_internal.h (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_subr/utf8proc/utf8proc_internal.h Tue Oct 31 09:39:59 2017 @@ -1,60 +1,60 @@ -#include "svn_private_config.h" -#if SVN_INTERNAL_UTF8PROC /* - * Copyright (c) 2009 Public Software Group e. V., Berlin, Germany + * Copyright (c) 2015 Steven G. Johnson, Jiahao Chen, Peter Colberg, Tony Kelman, Scott P. Jones, and other contributors. + * Copyright (c) 2009 Public Software Group e. V., Berlin, Germany * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ -/* - * File name: utf8proc.h +/** + * @mainpage + * + * utf8proc is a free/open-source (MIT/expat licensed) C library + * providing Unicode normalization, case-folding, and other operations + * for strings in the UTF-8 encoding, supporting Unicode version + * 8.0.0. See the utf8proc home page (http://julialang.org/utf8proc/) + * for downloads and other information, or the source code on github + * (https://github.com/JuliaLang/utf8proc). * - * Description: - * Header files for libutf8proc, which is a mapping tool for UTF-8 strings - * with following features: - * - decomposing and composing of strings - * - replacing compatibility characters with their equivalents - * - stripping of "default ignorable characters" - * like SOFT-HYPHEN or ZERO-WIDTH-SPACE - * - folding of certain characters for string comparison - * (e.g. HYPHEN U+2010 and MINUS U+2212 to ASCII "-") - * (see "LUMP" option) - * - optional rejection of strings containing non-assigned code points - * - stripping of control characters - * - stripping of character marks (accents, etc.) - * - transformation of LF, CRLF, CR and NEL to line-feed (LF) - * or to the unicode chararacters for paragraph separation (PS) - * or line separation (LS). - * - unicode case folding (for case insensitive string comparisons) - * - rejection of illegal UTF-8 data - * (i.e. UTF-8 encoded UTF-16 surrogates) - * - support for korean hangul characters - * Unicode Version 5.0.0 is supported. + * For the utf8proc API documentation, see: @ref utf8proc.h + * + * The features of utf8proc include: + * + * - Transformation of strings (@ref utf8proc_map) to: + * - decompose (@ref UTF8PROC_DECOMPOSE) or compose (@ref UTF8PROC_COMPOSE) Unicode combining characters (http://en.wikipedia.org/wiki/Combining_character) + * - canonicalize Unicode compatibility characters (@ref UTF8PROC_COMPAT) + * - strip "ignorable" (@ref UTF8PROC_IGNORE) characters, control characters (@ref UTF8PROC_STRIPCC), or combining characters such as accents (@ref UTF8PROC_STRIPMARK) + * - case-folding (@ref UTF8PROC_CASEFOLD) + * - Unicode normalization: @ref utf8proc_NFD, @ref utf8proc_NFC, @ref utf8proc_NFKD, @ref utf8proc_NFKC + * - Detecting grapheme boundaries (@ref utf8proc_grapheme_break and @ref UTF8PROC_CHARBOUND) + * - Character-width computation: @ref utf8proc_charwidth + * - Classification of characters by Unicode category: @ref utf8proc_category and @ref utf8proc_category_string + * - Encode (@ref utf8proc_encode_char) and decode (@ref utf8proc_iterate) Unicode codepoints to/from UTF-8. */ +/** @file */ #ifndef UTF8PROC_H #define UTF8PROC_H /** @name API version - * + * * The utf8proc API version MAJOR.MINOR.PATCH, following * semantic-versioning rules (http://semver.org) based on API * compatibility. @@ -63,66 +63,81 @@ * runtime version may append a string like "-dev" to the version number * for prerelease versions. * - * @note The shared-library version number in the Makefile may be different, + * @note The shared-library version number in the Makefile + * (and CMakeLists.txt, and MANIFEST) may be different, * being based on ABI compatibility rather than API compatibility. */ /** @{ */ /** The MAJOR version number (increased when backwards API compatibility is broken). */ -#define UTF8PROC_VERSION_MAJOR 1 +#define UTF8PROC_VERSION_MAJOR 2 /** The MINOR version number (increased when new functionality is added in a backwards-compatible manner). */ #define UTF8PROC_VERSION_MINOR 1 /** The PATCH version (increased for fixes that do not change the API). */ -#define UTF8PROC_VERSION_PATCH 5 +#define UTF8PROC_VERSION_PATCH 0 /** @} */ -/* - * Define UTF8PROC_INLINE and include utf8proc.c to embed a static - * version of utf8proc in your program or library without exporting - * any of its symbols. - */ -#ifdef UTF8PROC_INLINE -#define UTF8PROC_API static -#undef UTF8PROC_DATA_EXPORT -#define UTF8PROC_DATA static -#else -#define UTF8PROC_API -#define UTF8PROC_DATA_EXPORT -#define UTF8PROC_DATA -#endif - - #include <stdlib.h> #include <sys/types.h> - -#ifdef HAVE_STDINT_H -#include <stdint.h> -#else #include <apr.h> +typedef char utf8proc_int8_t; +typedef unsigned char utf8proc_uint8_t; +typedef apr_int16_t utf8proc_int16_t; +typedef apr_uint16_t utf8proc_uint16_t; +typedef apr_int32_t utf8proc_int32_t; +typedef apr_uint32_t utf8proc_uint32_t; #ifdef _MSC_VER -typedef apr_int8_t int8_t; -typedef apr_uint8_t uint8_t; -typedef apr_int16_t int16_t; -typedef apr_uint16_t uint16_t; -typedef apr_int32_t int32_t; -typedef apr_uint32_t uint32_t; +# ifdef _WIN64 +typedef apr_int64_t utf8proc_ssize_t; +typedef apr_uint64_t utf8proc_size_t; +# else +typedef apr_int32_t utf8proc_ssize_t; +typedef apr_uint32_t utf8proc_size_t; +# endif +#else +typedef apr_size_t utf8proc_size_t; +typedef apr_ssize_t utf8proc_ssize_t; #endif +#ifdef __cplusplus +typedef bool utf8proc_bool; +#elif defined HAVE_STDBOOL_H +# include <stdbool.h> +typedef bool utf8proc_bool; +#else +/* emulate C99 bool */ +# ifndef __bool_true_false_are_defined +# define false 0 +# define true 1 +# define __bool_true_false_are_defined 1 +# endif +typedef apr_byte_t utf8proc_bool; #endif +#include <limits.h> -#ifdef HAVE_STDBOOL_H -#include <stdbool.h> -#elif !defined(__cplusplus) -typedef uint8_t bool; -enum { false, true }; -#endif -#ifdef _MSC_VER -# ifdef _WIN64 -# define ssize_t __int64 -# else -# define ssize_t int -# endif +/* + * Define UTF8PROC_INLINE and include utf8proc.c to embed a static + * version of utf8proc in your program or library without exporting + * any of its symbols. + */ +#ifdef UTF8PROC_INLINE +# define UTF8PROC_DATA static +# undef UTF8PROC_DATA_EXPORT +# define UTF8PROC_DLLEXPORT static +#else +# define UTF8PROC_DATA +# define UTF8PROC_DATA_EXPORT +# ifdef _WIN32 +# ifdef UTF8PROC_EXPORTS +# define UTF8PROC_DLLEXPORT __declspec(dllexport) +# else +# define UTF8PROC_DLLEXPORT __declspec(dllimport) +# endif +# elif __GNUC__ >= 4 +# define UTF8PROC_DLLEXPORT __attribute__ ((visibility("default"))) +# else +# define UTF8PROC_DLLEXPORT +# endif #endif -#include <limits.h> #ifdef __cplusplus extern "C" { @@ -132,321 +147,562 @@ extern "C" { #define SSIZE_MAX ((size_t)SIZE_MAX/2) #endif -#define UTF8PROC_NULLTERM (1<<0) -#define UTF8PROC_STABLE (1<<1) -#define UTF8PROC_COMPAT (1<<2) -#define UTF8PROC_COMPOSE (1<<3) -#define UTF8PROC_DECOMPOSE (1<<4) -#define UTF8PROC_IGNORE (1<<5) -#define UTF8PROC_REJECTNA (1<<6) -#define UTF8PROC_NLF2LS (1<<7) -#define UTF8PROC_NLF2PS (1<<8) -#define UTF8PROC_NLF2LF (UTF8PROC_NLF2LS | UTF8PROC_NLF2PS) -#define UTF8PROC_STRIPCC (1<<9) -#define UTF8PROC_CASEFOLD (1<<10) -#define UTF8PROC_CHARBOUND (1<<11) -#define UTF8PROC_LUMP (1<<12) -#define UTF8PROC_STRIPMARK (1<<13) -/* - * Flags being regarded by several functions in the library: - * NULLTERM: The given UTF-8 input is NULL terminated. - * STABLE: Unicode Versioning Stability has to be respected. - * COMPAT: Compatiblity decomposition - * (i.e. formatting information is lost) - * COMPOSE: Return a result with composed characters. - * DECOMPOSE: Return a result with decomposed characters. - * IGNORE: Strip "default ignorable characters" - * REJECTNA: Return an error, if the input contains unassigned - * code points. - * NLF2LS: Indicating that NLF-sequences (LF, CRLF, CR, NEL) are - * representing a line break, and should be converted to the - * unicode character for line separation (LS). - * NLF2PS: Indicating that NLF-sequences are representing a paragraph - * break, and should be converted to the unicode character for - * paragraph separation (PS). - * NLF2LF: Indicating that the meaning of NLF-sequences is unknown. - * STRIPCC: Strips and/or convers control characters. - * NLF-sequences are transformed into space, except if one of - * the NLF2LS/PS/LF options is given. - * HorizontalTab (HT) and FormFeed (FF) are treated as a - * NLF-sequence in this case. - * All other control characters are simply removed. - * CASEFOLD: Performs unicode case folding, to be able to do a - * case-insensitive string comparison. - * CHARBOUND: Inserts 0xFF bytes at the beginning of each sequence which - * is representing a single grapheme cluster (see UAX#29). - * LUMP: Lumps certain characters together - * (e.g. HYPHEN U+2010 and MINUS U+2212 to ASCII "-"). - * (See lump.txt for details.) - * If NLF2LF is set, this includes a transformation of - * paragraph and line separators to ASCII line-feed (LF). - * STRIPMARK: Strips all character markings - * (non-spacing, spacing and enclosing) (i.e. accents) - * NOTE: this option works only with COMPOSE or DECOMPOSE +#ifndef UINT16_MAX +# define UINT16_MAX 65535U +#endif + +/** + * Option flags used by several functions in the library. */ +typedef enum { + /** The given UTF-8 input is NULL terminated. */ + UTF8PROC_NULLTERM = (1<<0), + /** Unicode Versioning Stability has to be respected. */ + UTF8PROC_STABLE = (1<<1), + /** Compatibility decomposition (i.e. formatting information is lost). */ + UTF8PROC_COMPAT = (1<<2), + /** Return a result with decomposed characters. */ + UTF8PROC_COMPOSE = (1<<3), + /** Return a result with decomposed characters. */ + UTF8PROC_DECOMPOSE = (1<<4), + /** Strip "default ignorable characters" such as SOFT-HYPHEN or ZERO-WIDTH-SPACE. */ + UTF8PROC_IGNORE = (1<<5), + /** Return an error, if the input contains unassigned codepoints. */ + UTF8PROC_REJECTNA = (1<<6), + /** + * Indicating that NLF-sequences (LF, CRLF, CR, NEL) are representing a + * line break, and should be converted to the codepoint for line + * separation (LS). + */ + UTF8PROC_NLF2LS = (1<<7), + /** + * Indicating that NLF-sequences are representing a paragraph break, and + * should be converted to the codepoint for paragraph separation + * (PS). + */ + UTF8PROC_NLF2PS = (1<<8), + /** Indicating that the meaning of NLF-sequences is unknown. */ + UTF8PROC_NLF2LF = (UTF8PROC_NLF2LS | UTF8PROC_NLF2PS), + /** Strips and/or convers control characters. + * + * NLF-sequences are transformed into space, except if one of the + * NLF2LS/PS/LF options is given. HorizontalTab (HT) and FormFeed (FF) + * are treated as a NLF-sequence in this case. All other control + * characters are simply removed. + */ + UTF8PROC_STRIPCC = (1<<9), + /** + * Performs unicode case folding, to be able to do a case-insensitive + * string comparison. + */ + UTF8PROC_CASEFOLD = (1<<10), + /** + * Inserts 0xFF bytes at the beginning of each sequence which is + * representing a single grapheme cluster (see UAX#29). + */ + UTF8PROC_CHARBOUND = (1<<11), + /** Lumps certain characters together. + * + * E.g. HYPHEN U+2010 and MINUS U+2212 to ASCII "-". See lump.md for details. + * + * If NLF2LF is set, this includes a transformation of paragraph and + * line separators to ASCII line-feed (LF). + */ + UTF8PROC_LUMP = (1<<12), + /** Strips all character markings. + * + * This includes non-spacing, spacing and enclosing (i.e. accents). + * @note This option works only with @ref UTF8PROC_COMPOSE or + * @ref UTF8PROC_DECOMPOSE + */ + UTF8PROC_STRIPMARK = (1<<13), +} utf8proc_option_t; +/** @name Error codes + * Error codes being returned by almost all functions. + */ +/** @{ */ +/** Memory could not be allocated. */ #define UTF8PROC_ERROR_NOMEM -1 +/** The given string is too long to be processed. */ #define UTF8PROC_ERROR_OVERFLOW -2 +/** The given string is not a legal UTF-8 string. */ #define UTF8PROC_ERROR_INVALIDUTF8 -3 +/** The @ref UTF8PROC_REJECTNA flag was set and an unassigned codepoint was found. */ #define UTF8PROC_ERROR_NOTASSIGNED -4 +/** Invalid options have been used. */ #define UTF8PROC_ERROR_INVALIDOPTS -5 -/* - * Error codes being returned by almost all functions: - * ERROR_NOMEM: Memory could not be allocated. - * ERROR_OVERFLOW: The given string is too long to be processed. - * ERROR_INVALIDUTF8: The given string is not a legal UTF-8 string. - * ERROR_NOTASSIGNED: The REJECTNA flag was set, - * and an unassigned code point was found. - * ERROR_INVALIDOPTS: Invalid options have been used. - */ +/** @} */ + +/* @name Types */ + +/** Holds the value of a property. */ +typedef utf8proc_int16_t utf8proc_propval_t; -typedef int16_t utf8proc_propval_t; +/** Struct containing information about a codepoint. */ typedef struct utf8proc_property_struct { + /** + * Unicode category. + * @see utf8proc_category_t. + */ utf8proc_propval_t category; utf8proc_propval_t combining_class; + /** + * Bidirectional class. + * @see utf8proc_bidi_class_t. + */ utf8proc_propval_t bidi_class; + /** + * @anchor Decomposition type. + * @see utf8proc_decomp_type_t. + */ utf8proc_propval_t decomp_type; - const int32_t *decomp_mapping; + utf8proc_uint16_t decomp_seqindex; + utf8proc_uint16_t casefold_seqindex; + utf8proc_uint16_t uppercase_seqindex; + utf8proc_uint16_t lowercase_seqindex; + utf8proc_uint16_t titlecase_seqindex; + utf8proc_uint16_t comb_index; unsigned bidi_mirrored:1; - int32_t uppercase_mapping; - int32_t lowercase_mapping; - int32_t titlecase_mapping; - int32_t comb1st_index; - int32_t comb2nd_index; unsigned comp_exclusion:1; + /** + * Can this codepoint be ignored? + * + * Used by @ref utf8proc_decompose_char when @ref UTF8PROC_IGNORE is + * passed as an option. + */ unsigned ignorable:1; unsigned control_boundary:1; - unsigned extend:1; - const int32_t *casefold_mapping; + /** The width of the codepoint. */ + unsigned charwidth:2; + unsigned pad:2; + /** + * Boundclass. + * @see utf8proc_boundclass_t. + */ + unsigned boundclass:8; } utf8proc_property_t; -#define UTF8PROC_CATEGORY_LU 1 -#define UTF8PROC_CATEGORY_LL 2 -#define UTF8PROC_CATEGORY_LT 3 -#define UTF8PROC_CATEGORY_LM 4 -#define UTF8PROC_CATEGORY_LO 5 -#define UTF8PROC_CATEGORY_MN 6 -#define UTF8PROC_CATEGORY_MC 7 -#define UTF8PROC_CATEGORY_ME 8 -#define UTF8PROC_CATEGORY_ND 9 -#define UTF8PROC_CATEGORY_NL 10 -#define UTF8PROC_CATEGORY_NO 11 -#define UTF8PROC_CATEGORY_PC 12 -#define UTF8PROC_CATEGORY_PD 13 -#define UTF8PROC_CATEGORY_PS 14 -#define UTF8PROC_CATEGORY_PE 15 -#define UTF8PROC_CATEGORY_PI 16 -#define UTF8PROC_CATEGORY_PF 17 -#define UTF8PROC_CATEGORY_PO 18 -#define UTF8PROC_CATEGORY_SM 19 -#define UTF8PROC_CATEGORY_SC 20 -#define UTF8PROC_CATEGORY_SK 21 -#define UTF8PROC_CATEGORY_SO 22 -#define UTF8PROC_CATEGORY_ZS 23 -#define UTF8PROC_CATEGORY_ZL 24 -#define UTF8PROC_CATEGORY_ZP 25 -#define UTF8PROC_CATEGORY_CC 26 -#define UTF8PROC_CATEGORY_CF 27 -#define UTF8PROC_CATEGORY_CS 28 -#define UTF8PROC_CATEGORY_CO 29 -#define UTF8PROC_CATEGORY_CN 30 -#define UTF8PROC_BIDI_CLASS_L 1 -#define UTF8PROC_BIDI_CLASS_LRE 2 -#define UTF8PROC_BIDI_CLASS_LRO 3 -#define UTF8PROC_BIDI_CLASS_R 4 -#define UTF8PROC_BIDI_CLASS_AL 5 -#define UTF8PROC_BIDI_CLASS_RLE 6 -#define UTF8PROC_BIDI_CLASS_RLO 7 -#define UTF8PROC_BIDI_CLASS_PDF 8 -#define UTF8PROC_BIDI_CLASS_EN 9 -#define UTF8PROC_BIDI_CLASS_ES 10 -#define UTF8PROC_BIDI_CLASS_ET 11 -#define UTF8PROC_BIDI_CLASS_AN 12 -#define UTF8PROC_BIDI_CLASS_CS 13 -#define UTF8PROC_BIDI_CLASS_NSM 14 -#define UTF8PROC_BIDI_CLASS_BN 15 -#define UTF8PROC_BIDI_CLASS_B 16 -#define UTF8PROC_BIDI_CLASS_S 17 -#define UTF8PROC_BIDI_CLASS_WS 18 -#define UTF8PROC_BIDI_CLASS_ON 19 -#define UTF8PROC_DECOMP_TYPE_FONT 1 -#define UTF8PROC_DECOMP_TYPE_NOBREAK 2 -#define UTF8PROC_DECOMP_TYPE_INITIAL 3 -#define UTF8PROC_DECOMP_TYPE_MEDIAL 4 -#define UTF8PROC_DECOMP_TYPE_FINAL 5 -#define UTF8PROC_DECOMP_TYPE_ISOLATED 6 -#define UTF8PROC_DECOMP_TYPE_CIRCLE 7 -#define UTF8PROC_DECOMP_TYPE_SUPER 8 -#define UTF8PROC_DECOMP_TYPE_SUB 9 -#define UTF8PROC_DECOMP_TYPE_VERTICAL 10 -#define UTF8PROC_DECOMP_TYPE_WIDE 11 -#define UTF8PROC_DECOMP_TYPE_NARROW 12 -#define UTF8PROC_DECOMP_TYPE_SMALL 13 -#define UTF8PROC_DECOMP_TYPE_SQUARE 14 -#define UTF8PROC_DECOMP_TYPE_FRACTION 15 -#define UTF8PROC_DECOMP_TYPE_COMPAT 16 - -#ifdef UTF8PROC_DATA_EXPORT -extern const int8_t utf8proc_utf8class[256]; +/** Unicode categories. */ +typedef enum { + UTF8PROC_CATEGORY_CN = 0, /**< Other, not assigned */ + UTF8PROC_CATEGORY_LU = 1, /**< Letter, uppercase */ + UTF8PROC_CATEGORY_LL = 2, /**< Letter, lowercase */ + UTF8PROC_CATEGORY_LT = 3, /**< Letter, titlecase */ + UTF8PROC_CATEGORY_LM = 4, /**< Letter, modifier */ + UTF8PROC_CATEGORY_LO = 5, /**< Letter, other */ + UTF8PROC_CATEGORY_MN = 6, /**< Mark, nonspacing */ + UTF8PROC_CATEGORY_MC = 7, /**< Mark, spacing combining */ + UTF8PROC_CATEGORY_ME = 8, /**< Mark, enclosing */ + UTF8PROC_CATEGORY_ND = 9, /**< Number, decimal digit */ + UTF8PROC_CATEGORY_NL = 10, /**< Number, letter */ + UTF8PROC_CATEGORY_NO = 11, /**< Number, other */ + UTF8PROC_CATEGORY_PC = 12, /**< Punctuation, connector */ + UTF8PROC_CATEGORY_PD = 13, /**< Punctuation, dash */ + UTF8PROC_CATEGORY_PS = 14, /**< Punctuation, open */ + UTF8PROC_CATEGORY_PE = 15, /**< Punctuation, close */ + UTF8PROC_CATEGORY_PI = 16, /**< Punctuation, initial quote */ + UTF8PROC_CATEGORY_PF = 17, /**< Punctuation, final quote */ + UTF8PROC_CATEGORY_PO = 18, /**< Punctuation, other */ + UTF8PROC_CATEGORY_SM = 19, /**< Symbol, math */ + UTF8PROC_CATEGORY_SC = 20, /**< Symbol, currency */ + UTF8PROC_CATEGORY_SK = 21, /**< Symbol, modifier */ + UTF8PROC_CATEGORY_SO = 22, /**< Symbol, other */ + UTF8PROC_CATEGORY_ZS = 23, /**< Separator, space */ + UTF8PROC_CATEGORY_ZL = 24, /**< Separator, line */ + UTF8PROC_CATEGORY_ZP = 25, /**< Separator, paragraph */ + UTF8PROC_CATEGORY_CC = 26, /**< Other, control */ + UTF8PROC_CATEGORY_CF = 27, /**< Other, format */ + UTF8PROC_CATEGORY_CS = 28, /**< Other, surrogate */ + UTF8PROC_CATEGORY_CO = 29, /**< Other, private use */ +} utf8proc_category_t; + +/** Bidirectional character classes. */ +typedef enum { + UTF8PROC_BIDI_CLASS_L = 1, /**< Left-to-Right */ + UTF8PROC_BIDI_CLASS_LRE = 2, /**< Left-to-Right Embedding */ + UTF8PROC_BIDI_CLASS_LRO = 3, /**< Left-to-Right Override */ + UTF8PROC_BIDI_CLASS_R = 4, /**< Right-to-Left */ + UTF8PROC_BIDI_CLASS_AL = 5, /**< Right-to-Left Arabic */ + UTF8PROC_BIDI_CLASS_RLE = 6, /**< Right-to-Left Embedding */ + UTF8PROC_BIDI_CLASS_RLO = 7, /**< Right-to-Left Override */ + UTF8PROC_BIDI_CLASS_PDF = 8, /**< Pop Directional Format */ + UTF8PROC_BIDI_CLASS_EN = 9, /**< European Number */ + UTF8PROC_BIDI_CLASS_ES = 10, /**< European Separator */ + UTF8PROC_BIDI_CLASS_ET = 11, /**< European Number Terminator */ + UTF8PROC_BIDI_CLASS_AN = 12, /**< Arabic Number */ + UTF8PROC_BIDI_CLASS_CS = 13, /**< Common Number Separator */ + UTF8PROC_BIDI_CLASS_NSM = 14, /**< Nonspacing Mark */ + UTF8PROC_BIDI_CLASS_BN = 15, /**< Boundary Neutral */ + UTF8PROC_BIDI_CLASS_B = 16, /**< Paragraph Separator */ + UTF8PROC_BIDI_CLASS_S = 17, /**< Segment Separator */ + UTF8PROC_BIDI_CLASS_WS = 18, /**< Whitespace */ + UTF8PROC_BIDI_CLASS_ON = 19, /**< Other Neutrals */ + UTF8PROC_BIDI_CLASS_LRI = 20, /**< Left-to-Right Isolate */ + UTF8PROC_BIDI_CLASS_RLI = 21, /**< Right-to-Left Isolate */ + UTF8PROC_BIDI_CLASS_FSI = 22, /**< First Strong Isolate */ + UTF8PROC_BIDI_CLASS_PDI = 23, /**< Pop Directional Isolate */ +} utf8proc_bidi_class_t; + +/** Decomposition type. */ +typedef enum { + UTF8PROC_DECOMP_TYPE_FONT = 1, /**< Font */ + UTF8PROC_DECOMP_TYPE_NOBREAK = 2, /**< Nobreak */ + UTF8PROC_DECOMP_TYPE_INITIAL = 3, /**< Initial */ + UTF8PROC_DECOMP_TYPE_MEDIAL = 4, /**< Medial */ + UTF8PROC_DECOMP_TYPE_FINAL = 5, /**< Final */ + UTF8PROC_DECOMP_TYPE_ISOLATED = 6, /**< Isolated */ + UTF8PROC_DECOMP_TYPE_CIRCLE = 7, /**< Circle */ + UTF8PROC_DECOMP_TYPE_SUPER = 8, /**< Super */ + UTF8PROC_DECOMP_TYPE_SUB = 9, /**< Sub */ + UTF8PROC_DECOMP_TYPE_VERTICAL = 10, /**< Vertical */ + UTF8PROC_DECOMP_TYPE_WIDE = 11, /**< Wide */ + UTF8PROC_DECOMP_TYPE_NARROW = 12, /**< Narrow */ + UTF8PROC_DECOMP_TYPE_SMALL = 13, /**< Small */ + UTF8PROC_DECOMP_TYPE_SQUARE = 14, /**< Square */ + UTF8PROC_DECOMP_TYPE_FRACTION = 15, /**< Fraction */ + UTF8PROC_DECOMP_TYPE_COMPAT = 16, /**< Compat */ +} utf8proc_decomp_type_t; + +/** Boundclass property. (TR29) */ +typedef enum { + UTF8PROC_BOUNDCLASS_START = 0, /**< Start */ + UTF8PROC_BOUNDCLASS_OTHER = 1, /**< Other */ + UTF8PROC_BOUNDCLASS_CR = 2, /**< Cr */ + UTF8PROC_BOUNDCLASS_LF = 3, /**< Lf */ + UTF8PROC_BOUNDCLASS_CONTROL = 4, /**< Control */ + UTF8PROC_BOUNDCLASS_EXTEND = 5, /**< Extend */ + UTF8PROC_BOUNDCLASS_L = 6, /**< L */ + UTF8PROC_BOUNDCLASS_V = 7, /**< V */ + UTF8PROC_BOUNDCLASS_T = 8, /**< T */ + UTF8PROC_BOUNDCLASS_LV = 9, /**< Lv */ + UTF8PROC_BOUNDCLASS_LVT = 10, /**< Lvt */ + UTF8PROC_BOUNDCLASS_REGIONAL_INDICATOR = 11, /**< Regional indicator */ + UTF8PROC_BOUNDCLASS_SPACINGMARK = 12, /**< Spacingmark */ + UTF8PROC_BOUNDCLASS_PREPEND = 13, /**< Prepend */ + UTF8PROC_BOUNDCLASS_ZWJ = 14, /**< Zero Width Joiner */ + UTF8PROC_BOUNDCLASS_E_BASE = 15, /**< Emoji Base */ + UTF8PROC_BOUNDCLASS_E_MODIFIER = 16, /**< Emoji Modifier */ + UTF8PROC_BOUNDCLASS_GLUE_AFTER_ZWJ = 17, /**< Glue_After_ZWJ */ + UTF8PROC_BOUNDCLASS_E_BASE_GAZ = 18, /**< E_BASE + GLUE_AFTER_ZJW */ +} utf8proc_boundclass_t; + +/** + * Function pointer type passed to @ref utf8proc_map_custom and + * @ref utf8proc_decompose_custom, which is used to specify a user-defined + * mapping of codepoints to be applied in conjunction with other mappings. + */ +typedef utf8proc_int32_t (*utf8proc_custom_func)(utf8proc_int32_t codepoint, void *data); + +#if defined(DOXYGEN) || defined(UTF8PROC_DATA_EXPORT) +/** + * Array containing the byte lengths of a UTF-8 encoded codepoint based + * on the first byte. + */ +UTF8PROC_DLLEXPORT extern const utf8proc_int8_t utf8proc_utf8class[256]; #endif -UTF8PROC_API -const char *utf8proc_version(void); +/** + * Returns the utf8proc API version as a string MAJOR.MINOR.PATCH + * (http://semver.org format), possibly with a "-dev" suffix for + * development versions. + */ +UTF8PROC_DLLEXPORT const char *utf8proc_version(void); + +/** + * Returns an informative error string for the given utf8proc error code + * (e.g. the error codes returned by @ref utf8proc_map). + */ +UTF8PROC_DLLEXPORT const char *utf8proc_errmsg(utf8proc_ssize_t errcode); + +/** + * Reads a single codepoint from the UTF-8 sequence being pointed to by `str`. + * The maximum number of bytes read is `strlen`, unless `strlen` is + * negative (in which case up to 4 bytes are read). + * + * If a valid codepoint could be read, it is stored in the variable + * pointed to by `codepoint_ref`, otherwise that variable will be set to -1. + * In case of success, the number of bytes read is returned; otherwise, a + * negative error code is returned. + */ +UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_iterate(const utf8proc_uint8_t *str, utf8proc_ssize_t strlen, utf8proc_int32_t *codepoint_ref); + +/** + * Check if a codepoint is valid (regardless of whether it has been + * assigned a value by the current Unicode standard). + * + * @return 1 if the given `codepoint` is valid and otherwise return 0. + */ +UTF8PROC_DLLEXPORT utf8proc_bool utf8proc_codepoint_valid(utf8proc_int32_t codepoint); -UTF8PROC_API -const char *utf8proc_errmsg(ssize_t errcode); -/* - * Returns a static error string for the given error code. +/** + * Encodes the codepoint as an UTF-8 string in the byte array pointed + * to by `dst`. This array must be at least 4 bytes long. + * + * In case of success the number of bytes written is returned, and + * otherwise 0 is returned. + * + * This function does not check whether `codepoint` is valid Unicode. */ +UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_encode_char(utf8proc_int32_t codepoint, utf8proc_uint8_t *dst); -UTF8PROC_API -ssize_t utf8proc_iterate(const uint8_t *str, ssize_t strlen, int32_t *dst); -/* - * Reads a single char from the UTF-8 sequence being pointed to by 'str'. - * The maximum number of bytes read is 'strlen', unless 'strlen' is - * negative. - * If a valid unicode char could be read, it is stored in the variable - * being pointed to by 'dst', otherwise that variable will be set to -1. - * In case of success the number of bytes read is returned, otherwise a - * negative error code is returned. +/** + * Look up the properties for a given codepoint. + * + * @param codepoint The Unicode codepoint. + * + * @returns + * A pointer to a (constant) struct containing information about + * the codepoint. + * @par + * If the codepoint is unassigned or invalid, a pointer to a special struct is + * returned in which `category` is 0 (@ref UTF8PROC_CATEGORY_CN). */ +UTF8PROC_DLLEXPORT const utf8proc_property_t *utf8proc_get_property(utf8proc_int32_t codepoint); -UTF8PROC_API -bool utf8proc_codepoint_valid(int32_t uc); -/* - * Returns 1, if the given unicode code-point is valid, otherwise 0. +/** Decompose a codepoint into an array of codepoints. + * + * @param codepoint the codepoint. + * @param dst the destination buffer. + * @param bufsize the size of the destination buffer. + * @param options one or more of the following flags: + * - @ref UTF8PROC_REJECTNA - return an error `codepoint` is unassigned + * - @ref UTF8PROC_IGNORE - strip "default ignorable" codepoints + * - @ref UTF8PROC_CASEFOLD - apply Unicode casefolding + * - @ref UTF8PROC_COMPAT - replace certain codepoints with their + * compatibility decomposition + * - @ref UTF8PROC_CHARBOUND - insert 0xFF bytes before each grapheme cluster + * - @ref UTF8PROC_LUMP - lump certain different codepoints together + * - @ref UTF8PROC_STRIPMARK - remove all character marks + * @param last_boundclass + * Pointer to an integer variable containing + * the previous codepoint's boundary class if the @ref UTF8PROC_CHARBOUND + * option is used. Otherwise, this parameter is ignored. + * + * @return + * In case of success, the number of codepoints written is returned; in case + * of an error, a negative error code is returned (@ref utf8proc_errmsg). + * @par + * If the number of written codepoints would be bigger than `bufsize`, the + * required buffer size is returned, while the buffer will be overwritten with + * undefined data. + */ +UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_char( + utf8proc_int32_t codepoint, utf8proc_int32_t *dst, utf8proc_ssize_t bufsize, + utf8proc_option_t options, int *last_boundclass +); + +/** + * The same as @ref utf8proc_decompose_char, but acts on a whole UTF-8 + * string and orders the decomposed sequences correctly. + * + * If the @ref UTF8PROC_NULLTERM flag in `options` is set, processing + * will be stopped, when a NULL byte is encounted, otherwise `strlen` + * bytes are processed. The result (in the form of 32-bit unicode + * codepoints) is written into the buffer being pointed to by + * `buffer` (which must contain at least `bufsize` entries). In case of + * success, the number of codepoints written is returned; in case of an + * error, a negative error code is returned (@ref utf8proc_errmsg). + * See @ref utf8proc_decompose_custom to supply additional transformations. + * + * If the number of written codepoints would be bigger than `bufsize`, the + * required buffer size is returned, while the buffer will be overwritten with + * undefined data. + */ +UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose( + const utf8proc_uint8_t *str, utf8proc_ssize_t strlen, + utf8proc_int32_t *buffer, utf8proc_ssize_t bufsize, utf8proc_option_t options +); + +/** + * The same as @ref utf8proc_decompose, but also takes a `custom_func` mapping function + * that is called on each codepoint in `str` before any other transformations + * (along with a `custom_data` pointer that is passed through to `custom_func`). + * The `custom_func` argument is ignored if it is `NULL`. See also @ref utf8proc_map_custom. + */ +UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_decompose_custom( + const utf8proc_uint8_t *str, utf8proc_ssize_t strlen, + utf8proc_int32_t *buffer, utf8proc_ssize_t bufsize, utf8proc_option_t options, + utf8proc_custom_func custom_func, void *custom_data +); + +/** + * Normalizes the sequence of `length` codepoints pointed to by `buffer` + * in-place (i.e., the result is also stored in `buffer`). + * + * @param buffer the (native-endian UTF-32) unicode codepoints to re-encode. + * @param length the length (in codepoints) of the buffer. + * @param options a bitwise or (`|`) of one or more of the following flags: + * - @ref UTF8PROC_NLF2LS - convert LF, CRLF, CR and NEL into LS + * - @ref UTF8PROC_NLF2PS - convert LF, CRLF, CR and NEL into PS + * - @ref UTF8PROC_NLF2LF - convert LF, CRLF, CR and NEL into LF + * - @ref UTF8PROC_STRIPCC - strip or convert all non-affected control characters + * - @ref UTF8PROC_COMPOSE - try to combine decomposed codepoints into composite + * codepoints + * - @ref UTF8PROC_STABLE - prohibit combining characters that would violate + * the unicode versioning stability + * + * @return + * In case of success, the length (in codepoints) of the normalized UTF-32 string is + * returned; otherwise, a negative error code is returned (@ref utf8proc_errmsg). + * + * @warning The entries of the array pointed to by `str` have to be in the + * range `0x0000` to `0x10FFFF`. Otherwise, the program might crash! */ +UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_normalize_utf32(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options); -UTF8PROC_API -ssize_t utf8proc_encode_char(int32_t uc, uint8_t *dst); -/* - * Encodes the unicode char with the code point 'uc' as an UTF-8 string in - * the byte array being pointed to by 'dst'. This array has to be at least - * 4 bytes long. - * In case of success the number of bytes written is returned, - * otherwise 0. - * This function does not check if 'uc' is a valid unicode code point. +/** + * Reencodes the sequence of `length` codepoints pointed to by `buffer` + * UTF-8 data in-place (i.e., the result is also stored in `buffer`). + * Can optionally normalize the UTF-32 sequence prior to UTF-8 conversion. + * + * @param buffer the (native-endian UTF-32) unicode codepoints to re-encode. + * @param length the length (in codepoints) of the buffer. + * @param options a bitwise or (`|`) of one or more of the following flags: + * - @ref UTF8PROC_NLF2LS - convert LF, CRLF, CR and NEL into LS + * - @ref UTF8PROC_NLF2PS - convert LF, CRLF, CR and NEL into PS + * - @ref UTF8PROC_NLF2LF - convert LF, CRLF, CR and NEL into LF + * - @ref UTF8PROC_STRIPCC - strip or convert all non-affected control characters + * - @ref UTF8PROC_COMPOSE - try to combine decomposed codepoints into composite + * codepoints + * - @ref UTF8PROC_STABLE - prohibit combining characters that would violate + * the unicode versioning stability + * - @ref UTF8PROC_CHARBOUND - insert 0xFF bytes before each grapheme cluster + * + * @return + * In case of success, the length (in bytes) of the resulting nul-terminated + * UTF-8 string is returned; otherwise, a negative error code is returned + * (@ref utf8proc_errmsg). + * + * @warning The amount of free space pointed to by `buffer` must + * exceed the amount of the input data by one byte, and the + * entries of the array pointed to by `str` have to be in the + * range `0x0000` to `0x10FFFF`. Otherwise, the program might crash! + */ +UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_reencode(utf8proc_int32_t *buffer, utf8proc_ssize_t length, utf8proc_option_t options); + +/** + * Given a pair of consecutive codepoints, return whether a grapheme break is + * permitted between them (as defined by the extended grapheme clusters in UAX#29). + * + * @param state Beginning with Version 29 (Unicode 9.0.0), this algorithm requires + * state to break graphemes. This state can be passed in as a pointer + * in the `state` argument and should initially be set to 0. If the + * state is not passed in (i.e. a null pointer is passed), UAX#29 rules + * GB10/12/13 which require this state will not be applied, essentially + * matching the rules in Unicode 8.0.0. + * + * @warning If the state parameter is used, `utf8proc_grapheme_break_stateful` must + * be called IN ORDER on ALL potential breaks in a string. */ +UTF8PROC_DLLEXPORT utf8proc_bool utf8proc_grapheme_break_stateful( + utf8proc_int32_t codepoint1, utf8proc_int32_t codepoint2, utf8proc_int32_t *state); -UTF8PROC_API -const utf8proc_property_t *utf8proc_get_property(int32_t uc); -/* - * Returns a pointer to a (constant) struct containing information about - * the unicode char with the given code point 'uc'. - * If the character is not existent a pointer to a special struct is - * returned, where 'category' is a NULL pointer. - * WARNING: The parameter 'uc' has to be in the range of 0x0000 to - * 0x10FFFF, otherwise the program might crash! +/** + * Same as @ref utf8proc_grapheme_break_stateful, except without support for the + * Unicode 9 additions to the algorithm. Supported for legacy reasons. */ +UTF8PROC_DLLEXPORT utf8proc_bool utf8proc_grapheme_break( + utf8proc_int32_t codepoint1, utf8proc_int32_t codepoint2); -UTF8PROC_API -ssize_t utf8proc_decompose_char( - int32_t uc, int32_t *dst, ssize_t bufsize, - int options, int *last_boundclass -); -/* - * Writes a decomposition of the unicode char 'uc' into the array being - * pointed to by 'dst'. - * Following flags in the 'options' field are regarded: - * REJECTNA: an unassigned unicode code point leads to an error - * IGNORE: "default ignorable" chars are stripped - * CASEFOLD: unicode casefolding is applied - * COMPAT: replace certain characters with their - * compatibility decomposition - * CHARBOUND: Inserts 0xFF bytes before each grapheme cluster - * LUMP: lumps certain different characters together - * STRIPMARK: removes all character marks - * The pointer 'last_boundclass' has to point to an integer variable which - * is storing the last character boundary class, if the CHARBOUND option - * is used. - * In case of success the number of chars written is returned, - * in case of an error, a negative error code is returned. - * If the number of written chars would be bigger than 'bufsize', - * the buffer (up to 'bufsize') has inpredictable data, and the needed - * buffer size is returned. - * WARNING: The parameter 'uc' has to be in the range of 0x0000 to - * 0x10FFFF, otherwise the program might crash! - */ - -UTF8PROC_API -ssize_t utf8proc_decompose( - const uint8_t *str, ssize_t strlen, - int32_t *buffer, ssize_t bufsize, int options -); -/* - * Does the same as 'utf8proc_decompose_char', but acts on a whole UTF-8 - * string, and orders the decomposed sequences correctly. - * If the NULLTERM flag in 'options' is set, processing will be stopped, - * when a NULL byte is encounted, otherwise 'strlen' bytes are processed. - * The result in form of unicode code points is written into the buffer - * being pointed to by 'buffer', having the length of 'bufsize' entries. - * In case of success the number of chars written is returned, - * in case of an error, a negative error code is returned. - * If the number of written chars would be bigger than 'bufsize', - * the buffer (up to 'bufsize') has inpredictable data, and the needed - * buffer size is returned. + +/** + * Given a codepoint `c`, return the codepoint of the corresponding + * lower-case character, if any; otherwise (if there is no lower-case + * variant, or if `c` is not a valid codepoint) return `c`. */ +UTF8PROC_DLLEXPORT utf8proc_int32_t utf8proc_tolower(utf8proc_int32_t c); -UTF8PROC_API -ssize_t utf8proc_reencode(int32_t *buffer, ssize_t length, int options); -/* - * Reencodes the sequence of unicode characters given by the pointer - * 'buffer' and 'length' as UTF-8. - * The result is stored in the same memory area where the data is read. - * Following flags in the 'options' field are regarded: - * NLF2LS: converts LF, CRLF, CR and NEL into LS - * NLF2PS: converts LF, CRLF, CR and NEL into PS - * NLF2LF: converts LF, CRLF, CR and NEL into LF - * STRIPCC: strips or converts all non-affected control characters - * COMPOSE: tries to combine decomposed characters into composite - * characters - * STABLE: prohibits combining characters which would violate - * the unicode versioning stability - * In case of success the length of the resulting UTF-8 string is - * returned, otherwise a negative error code is returned. - * WARNING: The amount of free space being pointed to by 'buffer', has to - * exceed the amount of the input data by one byte, and the - * entries of the array pointed to by 'str' have to be in the - * range of 0x0000 to 0x10FFFF, otherwise the program might - * crash! - */ - -UTF8PROC_API -ssize_t utf8proc_map( - const uint8_t *str, ssize_t strlen, uint8_t **dstptr, int options +/** + * Given a codepoint `c`, return the codepoint of the corresponding + * upper-case character, if any; otherwise (if there is no upper-case + * variant, or if `c` is not a valid codepoint) return `c`. + */ +UTF8PROC_DLLEXPORT utf8proc_int32_t utf8proc_toupper(utf8proc_int32_t c); + +/** + * Given a codepoint `c`, return the codepoint of the corresponding + * title-case character, if any; otherwise (if there is no title-case + * variant, or if `c` is not a valid codepoint) return `c`. + */ +UTF8PROC_DLLEXPORT utf8proc_int32_t utf8proc_totitle(utf8proc_int32_t c); + +/** + * Given a codepoint, return a character width analogous to `wcwidth(codepoint)`, + * except that a width of 0 is returned for non-printable codepoints + * instead of -1 as in `wcwidth`. + * + * @note + * If you want to check for particular types of non-printable characters, + * (analogous to `isprint` or `iscntrl`), use @ref utf8proc_category. */ +UTF8PROC_DLLEXPORT int utf8proc_charwidth(utf8proc_int32_t codepoint); + +/** + * Return the Unicode category for the codepoint (one of the + * @ref utf8proc_category_t constants.) + */ +UTF8PROC_DLLEXPORT utf8proc_category_t utf8proc_category(utf8proc_int32_t codepoint); + +/** + * Return the two-letter (nul-terminated) Unicode category string for + * the codepoint (e.g. `"Lu"` or `"Co"`). + */ +UTF8PROC_DLLEXPORT const char *utf8proc_category_string(utf8proc_int32_t codepoint); + +/** + * Maps the given UTF-8 string pointed to by `str` to a new UTF-8 + * string, allocated dynamically by `malloc` and returned via `dstptr`. + * + * If the @ref UTF8PROC_NULLTERM flag in the `options` field is set, + * the length is determined by a NULL terminator, otherwise the + * parameter `strlen` is evaluated to determine the string length, but + * in any case the result will be NULL terminated (though it might + * contain NULL characters with the string if `str` contained NULL + * characters). Other flags in the `options` field are passed to the + * functions defined above, and regarded as described. See also + * @ref utfproc_map_custom to supply a custom codepoint transformation. + * + * In case of success the length of the new string is returned, + * otherwise a negative error code is returned. + * + * @note The memory of the new UTF-8 string will have been allocated + * with `malloc`, and should therefore be deallocated with `free`. + */ +UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_map( + const utf8proc_uint8_t *str, utf8proc_ssize_t strlen, utf8proc_uint8_t **dstptr, utf8proc_option_t options ); -/* - * Maps the given UTF-8 string being pointed to by 'str' to a new UTF-8 - * string, which is allocated dynamically, and afterwards pointed to by - * the pointer being pointed to by 'dstptr'. - * If the NULLTERM flag in the 'options' field is set, the length is - * determined by a NULL terminator, otherwise the parameter 'strlen' is - * evaluated to determine the string length, but in any case the result - * will be NULL terminated (though it might contain NULL characters - * before). Other flags in the 'options' field are passed to the functions - * defined above, and regarded as described. - * In case of success the length of the new string is returned, - * otherwise a negative error code is returned. - * NOTICE: The memory of the new UTF-8 string will have been allocated with - * 'malloc', and has theirfore to be freed with 'free'. - */ - -UTF8PROC_API -uint8_t *utf8proc_NFD(const uint8_t *str); -UTF8PROC_API -uint8_t *utf8proc_NFC(const uint8_t *str); -UTF8PROC_API -uint8_t *utf8proc_NFKD(const uint8_t *str); -UTF8PROC_API -uint8_t *utf8proc_NFKC(const uint8_t *str); -/* - * Returns a pointer to newly allocated memory of a NFD, NFC, NFKD or NFKC - * normalized version of the null-terminated string 'str'. + +/** + * Like @ref utf8proc_map, but also takes a `custom_func` mapping function + * that is called on each codepoint in `str` before any other transformations + * (along with a `custom_data` pointer that is passed through to `custom_func`). + * The `custom_func` argument is ignored if it is `NULL`. + */ +UTF8PROC_DLLEXPORT utf8proc_ssize_t utf8proc_map_custom( + const utf8proc_uint8_t *str, utf8proc_ssize_t strlen, utf8proc_uint8_t **dstptr, utf8proc_option_t options, + utf8proc_custom_func custom_func, void *custom_data +); + +/** @name Unicode normalization + * + * Returns a pointer to newly allocated memory of a NFD, NFC, NFKD or NFKC + * normalized version of the null-terminated string `str`. These + * are shortcuts to calling @ref utf8proc_map with @ref UTF8PROC_NULLTERM + * combined with @ref UTF8PROC_STABLE and flags indicating the normalization. */ +/** @{ */ +/** NFD normalization (@ref UTF8PROC_DECOMPOSE). */ +UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFD(const utf8proc_uint8_t *str); +/** NFC normalization (@ref UTF8PROC_COMPOSE). */ +UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFC(const utf8proc_uint8_t *str); +/** NFKD normalization (@ref UTF8PROC_DECOMPOSE and @ref UTF8PROC_COMPAT). */ +UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKD(const utf8proc_uint8_t *str); +/** NFKC normalization (@ref UTF8PROC_COMPOSE and @ref UTF8PROC_COMPAT). */ +UTF8PROC_DLLEXPORT utf8proc_uint8_t *utf8proc_NFKC(const utf8proc_uint8_t *str); +/** @} */ #ifdef __cplusplus } #endif #endif -#endif /* SVN_INTERNAL_UTF8PROC */
Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_subr/version.c URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_subr/version.c?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_subr/version.c (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_subr/version.c Tue Oct 31 09:39:59 2017 @@ -271,7 +271,7 @@ svn_version__parse_version_string(svn_ve svn_boolean_t -svn_version__at_least(svn_version_t *version, +svn_version__at_least(const svn_version_t *version, int major, int minor, int patch) Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_crashrpt.c URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_crashrpt.c?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_crashrpt.c (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_crashrpt.c Tue Oct 31 09:39:59 2017 @@ -795,4 +795,11 @@ svn__unhandled_exception_filter(PEXCEPTI return EXCEPTION_EXECUTE_HANDLER; } #endif /* SVN_USE_WIN32_CRASHHANDLER */ +#else /* !WIN32 */ + +/* Silence OSX ranlib warnings about object files with no symbols. */ +#include <apr.h> +extern const apr_uint32_t svn__fake__win32_crashrpt; +const apr_uint32_t svn__fake__win32_crashrpt = 0xdeadbeef; + #endif /* WIN32 */ Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_crypto.c URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_crypto.c?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_crypto.c (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_crypto.c Tue Oct 31 09:39:59 2017 @@ -512,4 +512,11 @@ svn_auth__get_windows_ssl_server_authori } +#else /* !WIN32 */ + +/* Silence OSX ranlib warnings about object files with no symbols. */ +#include <apr.h> +extern const apr_uint32_t svn__fake__win32_crypto; +const apr_uint32_t svn__fake__win32_crypto = 0xdeadbeef; + #endif /* WIN32 */ Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_xlate.c URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_xlate.c?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_xlate.c (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_subr/win32_xlate.c Tue Oct 31 09:39:59 2017 @@ -248,4 +248,11 @@ svn_subr__win32_xlate_to_stringbuf(svn_s return APR_SUCCESS; } +#else /* !WIN32 */ + +/* Silence OSX ranlib warnings about object files with no symbols. */ +#include <apr.h> +extern const apr_uint32_t svn__fake__win32_xlate; +const apr_uint32_t svn__fake__win32_xlate = 0xdeadbeef; + #endif /* WIN32 */ Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_subr/x509parse.c URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_subr/x509parse.c?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_subr/x509parse.c (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_subr/x509parse.c Tue Oct 31 09:39:59 2017 @@ -472,6 +472,18 @@ x509_get_date(apr_time_t *when, /* apr_time_exp_t expects months to be zero indexed, 0=Jan, 11=Dec. */ xt.tm_mon -= 1; + /* range checks (as per definition of apr_time_exp_t in apr_time.h) */ + if (xt.tm_usec < 0 || + xt.tm_sec < 0 || xt.tm_sec > 61 || + xt.tm_min < 0 || xt.tm_min > 59 || + xt.tm_hour < 0 || xt.tm_hour > 23 || + xt.tm_mday < 1 || xt.tm_mday > 31 || + xt.tm_mon < 0 || xt.tm_mon > 11 || + xt.tm_year < 0 || + xt.tm_wday < 0 || xt.tm_wday > 6 || + xt.tm_yday < 0 || xt.tm_yday > 365) + return svn_error_create(SVN_ERR_X509_CERT_INVALID_DATE, NULL, NULL); + ret = apr_time_exp_gmt_get(when, &xt); if (ret) return svn_error_wrap_apr(ret, NULL); Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_wc/conflicts.c URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_wc/conflicts.c?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_wc/conflicts.c (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_wc/conflicts.c Tue Oct 31 09:39:59 2017 @@ -3844,7 +3844,6 @@ svn_wc__guess_incoming_move_target_nodes const char *victim_abspath, svn_node_kind_t victim_node_kind, const char *moved_to_repos_relpath, - svn_revnum_t rev, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { @@ -3855,7 +3854,7 @@ svn_wc__guess_incoming_move_target_nodes *possible_targets = apr_array_make(result_pool, 1, sizeof(const char *)); SVN_ERR(svn_wc__find_repos_node_in_wc(&candidates, wc_ctx->db, victim_abspath, - moved_to_repos_relpath, rev, + moved_to_repos_relpath, scratch_pool, scratch_pool)); /* Find a "useful move target" node in our set of candidates. Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_wc/upgrade.c URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_wc/upgrade.c?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_wc/upgrade.c (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_wc/upgrade.c Tue Oct 31 09:39:59 2017 @@ -653,178 +653,6 @@ ensure_repos_info(svn_wc_entry_t *entry, } -/* - * Read tree conflict descriptions from @a conflict_data. Set @a *conflicts - * to a hash of pointers to svn_wc_conflict_description2_t objects indexed by - * svn_wc_conflict_description2_t.local_abspath, all newly allocated in @a - * pool. @a dir_path is the path to the working copy directory whose conflicts - * are being read. The conflicts read are the tree conflicts on the immediate - * child nodes of @a dir_path. Do all allocations in @a pool. - * - * Note: There were some concerns about this function: - * - * ### this is BAD. the CONFLICTS structure should not be dependent upon - * ### DIR_PATH. each conflict should be labeled with an entry name, not - * ### a whole path. (and a path which happens to vary based upon invocation - * ### of the user client and these APIs) - * - * those assumptions were baked into former versions of the data model, so - * they have to stick around here. But they have been removed from the - * New Way. */ -static svn_error_t * -read_tree_conflicts(apr_hash_t **conflicts, - const char *conflict_data, - const char *dir_path, - apr_pool_t *pool) -{ - const svn_skel_t *skel; - apr_pool_t *iterpool; - - *conflicts = apr_hash_make(pool); - - if (conflict_data == NULL) - return SVN_NO_ERROR; - - skel = svn_skel__parse(conflict_data, strlen(conflict_data), pool); - if (skel == NULL) - return svn_error_create(SVN_ERR_WC_CORRUPT, NULL, - _("Error parsing tree conflict skel")); - - iterpool = svn_pool_create(pool); - for (skel = skel->children; skel != NULL; skel = skel->next) - { - const svn_wc_conflict_description2_t *conflict; - - svn_pool_clear(iterpool); - SVN_ERR(svn_wc__deserialize_conflict(&conflict, skel, dir_path, - pool, iterpool)); - if (conflict != NULL) - svn_hash_sets(*conflicts, - svn_dirent_basename(conflict->local_abspath, pool), - conflict); - } - svn_pool_destroy(iterpool); - - return SVN_NO_ERROR; -} - -/* */ -static svn_error_t * -migrate_single_tree_conflict_data(svn_sqlite__db_t *sdb, - const char *tree_conflict_data, - apr_int64_t wc_id, - const char *local_relpath, - apr_pool_t *scratch_pool) -{ - apr_hash_t *conflicts; - apr_hash_index_t *hi; - apr_pool_t *iterpool; - - SVN_ERR(read_tree_conflicts(&conflicts, tree_conflict_data, local_relpath, - scratch_pool)); - - iterpool = svn_pool_create(scratch_pool); - for (hi = apr_hash_first(scratch_pool, conflicts); - hi; - hi = apr_hash_next(hi)) - { - const svn_wc_conflict_description2_t *conflict = apr_hash_this_val(hi); - const char *conflict_relpath; - const char *conflict_data; - svn_sqlite__stmt_t *stmt; - svn_boolean_t have_row; - svn_skel_t *skel; - - svn_pool_clear(iterpool); - - conflict_relpath = svn_dirent_join(local_relpath, - svn_dirent_basename( - conflict->local_abspath, iterpool), - iterpool); - - SVN_ERR(svn_wc__serialize_conflict(&skel, conflict, iterpool, iterpool)); - conflict_data = svn_skel__unparse(skel, iterpool)->data; - - /* See if we need to update or insert an ACTUAL node. */ - SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, STMT_SELECT_ACTUAL_NODE)); - SVN_ERR(svn_sqlite__bindf(stmt, "is", wc_id, conflict_relpath)); - SVN_ERR(svn_sqlite__step(&have_row, stmt)); - SVN_ERR(svn_sqlite__reset(stmt)); - - if (have_row) - { - /* There is an existing ACTUAL row, so just update it. */ - SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, - STMT_UPDATE_ACTUAL_CONFLICT)); - } - else - { - /* We need to insert an ACTUAL row with the tree conflict data. */ - SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, - STMT_INSERT_ACTUAL_CONFLICT)); - } - - SVN_ERR(svn_sqlite__bindf(stmt, "iss", wc_id, conflict_relpath, - conflict_data)); - if (!have_row) - SVN_ERR(svn_sqlite__bind_text(stmt, 4, local_relpath)); - - SVN_ERR(svn_sqlite__step_done(stmt)); - } - - svn_pool_destroy(iterpool); - - return SVN_NO_ERROR; -} - - -/* */ -static svn_error_t * -migrate_tree_conflict_data(svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - svn_sqlite__stmt_t *stmt; - svn_boolean_t have_row; - apr_pool_t *iterpool = svn_pool_create(scratch_pool); - - /* Iterate over each node which has a set of tree conflicts, then insert - all of them into the new schema. */ - - SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, - STMT_UPGRADE_21_SELECT_OLD_TREE_CONFLICT)); - - /* Get all the existing tree conflict data. */ - SVN_ERR(svn_sqlite__step(&have_row, stmt)); - while (have_row) - { - apr_int64_t wc_id; - const char *local_relpath; - const char *tree_conflict_data; - - svn_pool_clear(iterpool); - - wc_id = svn_sqlite__column_int64(stmt, 0); - local_relpath = svn_sqlite__column_text(stmt, 1, iterpool); - tree_conflict_data = svn_sqlite__column_text(stmt, 2, iterpool); - - SVN_ERR(migrate_single_tree_conflict_data(sdb, tree_conflict_data, - wc_id, local_relpath, - iterpool)); - - /* We don't need to do anything but step over the previously - prepared statement. */ - SVN_ERR(svn_sqlite__step(&have_row, stmt)); - } - SVN_ERR(svn_sqlite__reset(stmt)); - - /* Erase all the old tree conflict data. */ - SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, - STMT_UPGRADE_21_ERASE_OLD_CONFLICTS)); - SVN_ERR(svn_sqlite__step_done(stmt)); - - svn_pool_destroy(iterpool); - return SVN_NO_ERROR; -} - /* ### need much more docco ### this function should be called within a sqlite transaction. it makes @@ -1318,234 +1146,6 @@ migrate_text_bases(apr_hash_t **text_bas return SVN_NO_ERROR; } -static svn_error_t * -bump_to_20(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_CREATE_NODES)); - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_20)); - return SVN_NO_ERROR; -} - -static svn_error_t * -bump_to_21(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_21)); - SVN_ERR(migrate_tree_conflict_data(sdb, scratch_pool)); - return SVN_NO_ERROR; -} - -static svn_error_t * -bump_to_22(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_22)); - return SVN_NO_ERROR; -} - -static svn_error_t * -bump_to_23(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - const char *wcroot_abspath = ((struct bump_baton *)baton)->wcroot_abspath; - svn_sqlite__stmt_t *stmt; - svn_boolean_t have_row; - - SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, - STMT_UPGRADE_23_HAS_WORKING_NODES)); - SVN_ERR(svn_sqlite__step(&have_row, stmt)); - SVN_ERR(svn_sqlite__reset(stmt)); - if (have_row) - return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL, - _("The working copy at '%s' is format 22 with " - "WORKING nodes; use a format 22 client to " - "diff/revert before using this client"), - wcroot_abspath); - - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_23)); - return SVN_NO_ERROR; -} - -static svn_error_t * -bump_to_24(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_24)); - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_CREATE_NODES_TRIGGERS)); - return SVN_NO_ERROR; -} - -static svn_error_t * -bump_to_25(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_25)); - return SVN_NO_ERROR; -} - -static svn_error_t * -bump_to_26(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_26)); - return SVN_NO_ERROR; -} - -static svn_error_t * -bump_to_27(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - const char *wcroot_abspath = ((struct bump_baton *)baton)->wcroot_abspath; - svn_sqlite__stmt_t *stmt; - svn_boolean_t have_row; - - SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, - STMT_UPGRADE_27_HAS_ACTUAL_NODES_CONFLICTS)); - SVN_ERR(svn_sqlite__step(&have_row, stmt)); - SVN_ERR(svn_sqlite__reset(stmt)); - if (have_row) - return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL, - _("The working copy at '%s' is format 26 with " - "conflicts; use a format 26 client to resolve " - "before using this client"), - wcroot_abspath); - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_27)); - return SVN_NO_ERROR; -} - -static svn_error_t * -bump_to_28(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_28)); - return SVN_NO_ERROR; -} - -/* If FINFO indicates that ABSPATH names a file, rename it to - * '<ABSPATH>.svn-base'. - * - * Ignore any file whose name is not the expected length, in order to make - * life easier for any developer who runs this code twice or has some - * non-standard files in the pristine directory. - * - * A callback for bump_to_29(), implementing #svn_io_walk_func_t. */ -static svn_error_t * -rename_pristine_file(void *baton, - const char *abspath, - const apr_finfo_t *finfo, - apr_pool_t *pool) -{ - if (finfo->filetype == APR_REG - && (strlen(svn_dirent_basename(abspath, pool)) - == PRISTINE_BASENAME_OLD_LEN)) - { - const char *new_abspath - = apr_pstrcat(pool, abspath, PRISTINE_STORAGE_EXT, SVN_VA_NULL); - - SVN_ERR(svn_io_file_rename2(abspath, new_abspath, FALSE, pool)); - } - return SVN_NO_ERROR; -} - -static svn_error_t * -upgrade_externals(struct bump_baton *bb, - svn_sqlite__db_t *sdb, - apr_pool_t *scratch_pool) -{ - svn_sqlite__stmt_t *stmt; - svn_sqlite__stmt_t *stmt_add; - svn_boolean_t have_row; - apr_pool_t *iterpool; - - SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, - STMT_SELECT_EXTERNAL_PROPERTIES)); - - SVN_ERR(svn_sqlite__get_statement(&stmt_add, sdb, - STMT_INSERT_EXTERNAL)); - - /* ### For this intermediate upgrade we just assume WC_ID = 1. - ### Before this bump we lost track of externals all the time, - ### so lets keep this easy. */ - SVN_ERR(svn_sqlite__bindf(stmt, "is", (apr_int64_t)1, "")); - - SVN_ERR(svn_sqlite__step(&have_row, stmt)); - - iterpool = svn_pool_create(scratch_pool); - while (have_row) - { - apr_hash_t *props; - const char *externals; - - svn_pool_clear(iterpool); - - SVN_ERR(svn_sqlite__column_properties(&props, stmt, 0, - iterpool, iterpool)); - - externals = svn_prop_get_value(props, SVN_PROP_EXTERNALS); - - if (externals) - { - apr_array_header_t *ext; - const char *local_relpath; - const char *local_abspath; - int i; - - local_relpath = svn_sqlite__column_text(stmt, 1, NULL); - local_abspath = svn_dirent_join(bb->wcroot_abspath, local_relpath, - iterpool); - - SVN_ERR(svn_wc_parse_externals_description3(&ext, local_abspath, - externals, FALSE, - iterpool)); - - for (i = 0; i < ext->nelts; i++) - { - const svn_wc_external_item2_t *item; - const char *item_relpath; - - item = APR_ARRAY_IDX(ext, i, const svn_wc_external_item2_t *); - item_relpath = svn_relpath_join(local_relpath, item->target_dir, - iterpool); - - /* Insert dummy externals definitions: Insert an unknown - external, to make sure it will be cleaned up when it is not - updated on the next update. */ - SVN_ERR(svn_sqlite__bindf(stmt_add, "isssssis", - (apr_int64_t)1, /* wc_id */ - item_relpath, - svn_relpath_dirname(item_relpath, - iterpool), - "normal", - "unknown", - local_relpath, - (apr_int64_t)1, /* repos_id */ - "" /* repos_relpath */)); - SVN_ERR(svn_sqlite__insert(NULL, stmt_add)); - } - } - - SVN_ERR(svn_sqlite__step(&have_row, stmt)); - } - - svn_pool_destroy(iterpool); - return svn_error_trace(svn_sqlite__reset(stmt)); -} - -static svn_error_t * -bump_to_29(void *baton, svn_sqlite__db_t *sdb, apr_pool_t *scratch_pool) -{ - struct bump_baton *bb = baton; - const char *wcroot_abspath = bb->wcroot_abspath; - const char *pristine_dir_abspath; - - /* Rename all pristine files, adding a ".svn-base" suffix. */ - pristine_dir_abspath = svn_dirent_join_many(scratch_pool, wcroot_abspath, - svn_wc_get_adm_dir(scratch_pool), - PRISTINE_STORAGE_RELPATH, - SVN_VA_NULL); - SVN_ERR(svn_io_dir_walk2(pristine_dir_abspath, APR_FINFO_MIN, - rename_pristine_file, NULL, scratch_pool)); - - /* Externals */ - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_CREATE_EXTERNALS)); - - SVN_ERR(upgrade_externals(bb, sdb, scratch_pool)); - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_29)); - return SVN_NO_ERROR; -} - svn_error_t * svn_wc__upgrade_conflict_skel_from_raw(svn_skel_t **conflicts, svn_wc__db_t *db, @@ -1774,41 +1374,10 @@ bump_to_31(void *baton, apr_pool_t *iterpool = svn_pool_create(scratch_pool); apr_array_header_t *empty_iprops = apr_array_make( scratch_pool, 0, sizeof(svn_prop_inherited_item_t *)); - svn_boolean_t iprops_column_exists = FALSE; svn_error_t *err; - /* Add the inherited_props column to NODES if it does not yet exist. - * - * When using a format >= 31 client to upgrade from old formats which - * did not yet have a NODES table, the inherited_props column has - * already been created as part of the NODES table. Attemping to add - * the inherited_props column will raise an error in this case, so check - * if the column exists first. - * - * Checking for the existence of a column before ALTER TABLE is not - * possible within SQLite. We need to run a separate query and evaluate - * its result in C first. - */ - SVN_ERR(svn_sqlite__get_statement(&stmt, sdb, STMT_PRAGMA_TABLE_INFO_NODES)); - SVN_ERR(svn_sqlite__step(&have_row, stmt)); - while (have_row) - { - const char *column_name = svn_sqlite__column_text(stmt, 1, NULL); - - if (strcmp(column_name, "inherited_props") == 0) - { - iprops_column_exists = TRUE; - break; - } - - SVN_ERR(svn_sqlite__step(&have_row, stmt)); - } - SVN_ERR(svn_sqlite__reset(stmt)); - if (!iprops_column_exists) - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_31_ALTER_TABLE)); - /* Run additional statements to finalize the upgrade to format 31. */ - SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_31_FINALIZE)); + SVN_ERR(svn_sqlite__exec_statements(sdb, STMT_UPGRADE_TO_31)); /* Set inherited_props to an empty array for the roots of all switched subtrees in the WC. This allows subsequent updates @@ -2090,6 +1659,15 @@ svn_wc__upgrade_sdb(int *result_format, svn_dirent_local_style(wcroot_abspath, scratch_pool), start_format); + else if (start_format < 29) + return svn_error_createf(SVN_ERR_WC_UPGRADE_REQUIRED, NULL, + _("Working copy '%s' is an old development " + "version (format %d); to upgrade it, " + "use a Subversion 1.7-1.9 client, then " + "use the current client"), + svn_dirent_local_style(wcroot_abspath, + scratch_pool), + start_format); /* ### need lock-out. only one upgrade at a time. note that other code ### cannot use this un-upgraded database until we finish the upgrade. */ @@ -2098,66 +1676,6 @@ svn_wc__upgrade_sdb(int *result_format, intentional. */ switch (start_format) { - case 19: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_20, &bb, - scratch_pool)); - *result_format = 20; - /* FALLTHROUGH */ - - case 20: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_21, &bb, - scratch_pool)); - *result_format = 21; - /* FALLTHROUGH */ - - case 21: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_22, &bb, - scratch_pool)); - *result_format = 22; - /* FALLTHROUGH */ - - case 22: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_23, &bb, - scratch_pool)); - *result_format = 23; - /* FALLTHROUGH */ - - case 23: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_24, &bb, - scratch_pool)); - *result_format = 24; - /* FALLTHROUGH */ - - case 24: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_25, &bb, - scratch_pool)); - *result_format = 25; - /* FALLTHROUGH */ - - case 25: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_26, &bb, - scratch_pool)); - *result_format = 26; - /* FALLTHROUGH */ - - case 26: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_27, &bb, - scratch_pool)); - *result_format = 27; - /* FALLTHROUGH */ - - case 27: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_28, &bb, - scratch_pool)); - *result_format = 28; - /* FALLTHROUGH */ - - case 28: - SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_29, &bb, - scratch_pool)); - *result_format = 29; - /* FALLTHROUGH */ - case 29: SVN_ERR(svn_sqlite__with_transaction(sdb, bump_to_30, &bb, scratch_pool)); Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc-metadata.sql URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc-metadata.sql?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc-metadata.sql (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc-metadata.sql Tue Oct 31 09:39:59 2017 @@ -229,11 +229,6 @@ CREATE TABLE WC_LOCK ( ); -PRAGMA user_version = --- define: SVN_WC__VERSION -; - - /* ------------------------------------------------------------------------- */ /* The NODES table describes the way WORKING nodes are layered on top of @@ -279,7 +274,6 @@ PRAGMA user_version = An 'svn revert foo/bar' would remove the NODES of (2). */ --- STMT_CREATE_NODES CREATE TABLE NODES ( /* Working copy location related fields */ @@ -503,8 +497,6 @@ CREATE VIEW NODES_BASE AS SELECT * FROM nodes WHERE op_depth = 0; --- STMT_CREATE_NODES_TRIGGERS - CREATE TRIGGER nodes_insert_trigger AFTER INSERT ON nodes WHEN NEW.checksum IS NOT NULL @@ -532,8 +524,6 @@ BEGIN WHERE checksum = OLD.checksum; END; --- STMT_CREATE_EXTERNALS - CREATE TABLE EXTERNALS ( /* Working copy location related fields (like NODES)*/ @@ -572,6 +562,12 @@ CREATE UNIQUE INDEX I_EXTERNALS_DEFINED def_local_relpath, local_relpath); + +PRAGMA user_version = +-- define: SVN_WC__VERSION +; + + /* ------------------------------------------------------------------------- */ /* This statement provides SQLite with the necessary information about our indexes to make better decisions in the query planner. @@ -630,208 +626,6 @@ INSERT INTO sqlite_stat1(tbl, idx, stat) ANALYZE sqlite_master; /* Loads sqlite_stat1 data for query optimizer */ /* ------------------------------------------------------------------------- */ -/* Format 20 introduces NODES and removes BASE_NODE and WORKING_NODE */ - --- STMT_UPGRADE_TO_20 - -UPDATE BASE_NODE SET checksum = (SELECT checksum FROM pristine - WHERE md5_checksum = BASE_NODE.checksum) -WHERE EXISTS (SELECT 1 FROM pristine WHERE md5_checksum = BASE_NODE.checksum); - -UPDATE WORKING_NODE SET checksum = (SELECT checksum FROM pristine - WHERE md5_checksum = WORKING_NODE.checksum) -WHERE EXISTS (SELECT 1 FROM pristine - WHERE md5_checksum = WORKING_NODE.checksum); - -INSERT INTO NODES ( - wc_id, local_relpath, op_depth, parent_relpath, - repos_id, repos_path, revision, - presence, depth, moved_here, moved_to, kind, - changed_revision, changed_date, changed_author, - checksum, properties, translated_size, last_mod_time, - dav_cache, symlink_target, file_external ) -SELECT wc_id, local_relpath, 0 /*op_depth*/, parent_relpath, - repos_id, repos_relpath, revnum, - presence, depth, NULL /*moved_here*/, NULL /*moved_to*/, kind, - changed_rev, changed_date, changed_author, - checksum, properties, translated_size, last_mod_time, - dav_cache, symlink_target, file_external -FROM BASE_NODE; -INSERT INTO NODES ( - wc_id, local_relpath, op_depth, parent_relpath, - repos_id, repos_path, revision, - presence, depth, moved_here, moved_to, kind, - changed_revision, changed_date, changed_author, - checksum, properties, translated_size, last_mod_time, - dav_cache, symlink_target, file_external ) -SELECT wc_id, local_relpath, 2 /*op_depth*/, parent_relpath, - copyfrom_repos_id, copyfrom_repos_path, copyfrom_revnum, - presence, depth, NULL /*moved_here*/, NULL /*moved_to*/, kind, - changed_rev, changed_date, changed_author, - checksum, properties, translated_size, last_mod_time, - NULL /*dav_cache*/, symlink_target, NULL /*file_external*/ -FROM WORKING_NODE; - -DROP TABLE BASE_NODE; -DROP TABLE WORKING_NODE; - -PRAGMA user_version = 20; - - -/* ------------------------------------------------------------------------- */ - -/* Format 21 involves no schema changes, it moves the tree conflict victim - information to victime nodes, rather than parents. */ - --- STMT_UPGRADE_TO_21 -PRAGMA user_version = 21; - -/* For format 21 bump code */ --- STMT_UPGRADE_21_SELECT_OLD_TREE_CONFLICT -SELECT wc_id, local_relpath, tree_conflict_data -FROM actual_node -WHERE tree_conflict_data IS NOT NULL - -/* For format 21 bump code */ --- STMT_UPGRADE_21_ERASE_OLD_CONFLICTS -UPDATE actual_node SET tree_conflict_data = NULL - -/* ------------------------------------------------------------------------- */ - -/* Format 22 simply moves the tree conflict information from the conflict_data - column to the tree_conflict_data column. */ - --- STMT_UPGRADE_TO_22 -UPDATE actual_node SET tree_conflict_data = conflict_data; -UPDATE actual_node SET conflict_data = NULL; - -PRAGMA user_version = 22; - - -/* ------------------------------------------------------------------------- */ - -/* Format 23 involves no schema changes, it introduces multi-layer - op-depth processing for NODES. */ - --- STMT_UPGRADE_TO_23 -PRAGMA user_version = 23; - --- STMT_UPGRADE_23_HAS_WORKING_NODES -SELECT 1 FROM nodes WHERE op_depth > 0 -LIMIT 1 - -/* ------------------------------------------------------------------------- */ - -/* Format 24 involves no schema changes; it starts using the pristine - table's refcount column correctly. */ - --- STMT_UPGRADE_TO_24 -UPDATE pristine SET refcount = - (SELECT COUNT(*) FROM nodes - WHERE checksum = pristine.checksum /*OR checksum = pristine.md5_checksum*/); - -PRAGMA user_version = 24; - -/* ------------------------------------------------------------------------- */ - -/* Format 25 introduces the NODES_CURRENT view. */ - --- STMT_UPGRADE_TO_25 -DROP VIEW IF EXISTS NODES_CURRENT; -CREATE VIEW NODES_CURRENT AS - SELECT * FROM nodes - JOIN (SELECT wc_id, local_relpath, MAX(op_depth) AS op_depth FROM nodes - GROUP BY wc_id, local_relpath) AS filter - ON nodes.wc_id = filter.wc_id - AND nodes.local_relpath = filter.local_relpath - AND nodes.op_depth = filter.op_depth; - -PRAGMA user_version = 25; - -/* ------------------------------------------------------------------------- */ - -/* Format 26 introduces the NODES_BASE view. */ - --- STMT_UPGRADE_TO_26 -DROP VIEW IF EXISTS NODES_BASE; -CREATE VIEW NODES_BASE AS - SELECT * FROM nodes - WHERE op_depth = 0; - -PRAGMA user_version = 26; - -/* ------------------------------------------------------------------------- */ - -/* Format 27 involves no schema changes, it introduces stores - conflict files as relpaths rather than names in ACTUAL_NODE. */ - --- STMT_UPGRADE_TO_27 -PRAGMA user_version = 27; - -/* For format 27 bump code */ --- STMT_UPGRADE_27_HAS_ACTUAL_NODES_CONFLICTS -SELECT 1 FROM actual_node -WHERE NOT ((prop_reject IS NULL) AND (conflict_old IS NULL) - AND (conflict_new IS NULL) AND (conflict_working IS NULL) - AND (tree_conflict_data IS NULL)) -LIMIT 1 - - -/* ------------------------------------------------------------------------- */ - -/* Format 28 involves no schema changes, it only converts MD5 pristine - references to SHA1. */ - --- STMT_UPGRADE_TO_28 - -UPDATE NODES SET checksum = (SELECT checksum FROM pristine - WHERE md5_checksum = nodes.checksum) -WHERE EXISTS (SELECT 1 FROM pristine WHERE md5_checksum = nodes.checksum); - -PRAGMA user_version = 28; - -/* ------------------------------------------------------------------------- */ - -/* Format 29 introduces the EXTERNALS table (See STMT_CREATE_TRIGGERS) and - optimizes a few trigger definitions. ... */ - --- STMT_UPGRADE_TO_29 - -DROP TRIGGER IF EXISTS nodes_update_checksum_trigger; -DROP TRIGGER IF EXISTS nodes_insert_trigger; -DROP TRIGGER IF EXISTS nodes_delete_trigger; - -CREATE TRIGGER nodes_update_checksum_trigger -AFTER UPDATE OF checksum ON nodes -WHEN NEW.checksum IS NOT OLD.checksum - /* AND (NEW.checksum IS NOT NULL OR OLD.checksum IS NOT NULL) */ -BEGIN - UPDATE pristine SET refcount = refcount + 1 - WHERE checksum = NEW.checksum; - UPDATE pristine SET refcount = refcount - 1 - WHERE checksum = OLD.checksum; -END; - -CREATE TRIGGER nodes_insert_trigger -AFTER INSERT ON nodes -WHEN NEW.checksum IS NOT NULL -BEGIN - UPDATE pristine SET refcount = refcount + 1 - WHERE checksum = NEW.checksum; -END; - -CREATE TRIGGER nodes_delete_trigger -AFTER DELETE ON nodes -WHEN OLD.checksum IS NOT NULL -BEGIN - UPDATE pristine SET refcount = refcount - 1 - WHERE checksum = OLD.checksum; -END; - -PRAGMA user_version = 29; - -/* ------------------------------------------------------------------------- */ - /* Format 30 creates a new NODES index for move information, and a new PRISTINE index for the md5_checksum column. It also activates use of skel-based conflict storage -- see notes/wc-ng/conflict-storage-2.0. @@ -870,9 +664,9 @@ WHERE wc_id = ?1 and local_relpath = ?2 /* Format 31 adds the inherited_props column to the NODES table. C code then initializes the update/switch roots to make sure future updates fetch the inherited properties */ --- STMT_UPGRADE_TO_31_ALTER_TABLE +-- STMT_UPGRADE_TO_31 ALTER TABLE NODES ADD COLUMN inherited_props BLOB; --- STMT_UPGRADE_TO_31_FINALIZE + DROP INDEX IF EXISTS I_ACTUAL_CHANGELIST; DROP INDEX IF EXISTS I_EXTERNALS_PARENT; @@ -906,25 +700,8 @@ WHERE l.op_depth = 0 /* ------------------------------------------------------------------------- */ /* Format 32 .... */ --- STMT_UPGRADE_TO_32 - -/* Drop old index. ### Remove this part from the upgrade to 31 once bumped */ -DROP INDEX IF EXISTS I_ACTUAL_CHANGELIST; -DROP INDEX IF EXISTS I_EXTERNALS_PARENT; -CREATE INDEX I_EXTERNALS_PARENT ON EXTERNALS (wc_id, parent_relpath); - -DROP INDEX I_NODES_PARENT; -CREATE UNIQUE INDEX I_NODES_PARENT ON NODES (wc_id, parent_relpath, - local_relpath, op_depth); - -DROP INDEX I_ACTUAL_PARENT; -CREATE UNIQUE INDEX I_ACTUAL_PARENT ON ACTUAL_NODE (wc_id, parent_relpath, - local_relpath); - -/* ------------------------------------------------------------------------- */ - -/* Format YYY introduces new handling for conflict information. */ --- format: YYY +/* -- STMT_UPGRADE_TO_32 +PRAGMA user_version = 32; */ /* ------------------------------------------------------------------------- */ Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc-queries.sql URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc-queries.sql?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc-queries.sql (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc-queries.sql Tue Oct 31 09:39:59 2017 @@ -1293,7 +1293,7 @@ PRAGMA journal_mode = DELETE -- STMT_FIND_REPOS_PATH_IN_WC SELECT local_relpath FROM nodes_current - WHERE wc_id = ?1 AND repos_path = ?2 AND revision = ?3 + WHERE wc_id = ?1 AND repos_path = ?2 /* ------------------------------------------------------------------------- */ Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc_db.c URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc_db.c?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc_db.c (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc_db.c Tue Oct 31 09:39:59 2017 @@ -1371,9 +1371,6 @@ init_db(/* output values */ /* Create the database's schema. */ SVN_ERR(svn_sqlite__exec_statements(db, STMT_CREATE_SCHEMA)); - SVN_ERR(svn_sqlite__exec_statements(db, STMT_CREATE_NODES)); - SVN_ERR(svn_sqlite__exec_statements(db, STMT_CREATE_NODES_TRIGGERS)); - SVN_ERR(svn_sqlite__exec_statements(db, STMT_CREATE_EXTERNALS)); SVN_ERR(svn_wc__db_install_schema_statistics(db, scratch_pool)); @@ -16585,7 +16582,6 @@ svn_wc__find_repos_node_in_wc(apr_array_ svn_wc__db_t *db, const char *wri_abspath, const char *repos_relpath, - svn_revnum_t rev, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { @@ -16603,7 +16599,7 @@ svn_wc__find_repos_node_in_wc(apr_array_ SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb, STMT_FIND_REPOS_PATH_IN_WC)); - SVN_ERR(svn_sqlite__bindf(stmt, "isr", wcroot->wc_id, repos_relpath, rev)); + SVN_ERR(svn_sqlite__bindf(stmt, "is", wcroot->wc_id, repos_relpath)); SVN_ERR(svn_sqlite__step(&have_row, stmt)); *local_abspath_list = apr_array_make(result_pool, have_row ? 1 : 0, Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc_db.h URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc_db.h?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc_db.h (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wc_db.h Tue Oct 31 09:39:59 2017 @@ -3489,8 +3489,7 @@ svn_wc__required_lock_for_resolve(const /* Return an array of const char * elements, which represent local absolute * paths for nodes, within the working copy indicated by WRI_ABSPATH, which - * correspond to REPOS_RELPATH@REV. - * If no such nodes exist, return an empty array. + * correspond to REPOS_RELPATH. If no such nodes exist, return an empty array. * * Note that this function returns each and every such node that is known * in the WC, including, for example, nodes that were children of a directory @@ -3501,7 +3500,6 @@ svn_wc__find_repos_node_in_wc(apr_array_ svn_wc__db_t *db, const char *wri_abspath, const char *repos_relpath, - svn_revnum_t rev, apr_pool_t *result_pool, apr_pool_t *scratch_pool); /* @} */ Modified: subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wcroot_anchor.c URL: http://svn.apache.org/viewvc/subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wcroot_anchor.c?rev=1813860&r1=1813859&r2=1813860&view=diff ============================================================================== --- subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wcroot_anchor.c (original) +++ subversion/branches/shelve-checkpoint/subversion/libsvn_wc/wcroot_anchor.c Tue Oct 31 09:39:59 2017 @@ -189,11 +189,11 @@ svn_wc__get_shelves_dir(char **dir, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { - const char *wc_adm_dir; + const char *wcroot_abspath; - SVN_ERR(svn_wc__get_wcroot(&wc_adm_dir, wc_ctx, local_abspath, + SVN_ERR(svn_wc__get_wcroot(&wcroot_abspath, wc_ctx, local_abspath, scratch_pool, scratch_pool)); - *dir = svn_dirent_join(wc_adm_dir, ".svn/shelves", result_pool); + *dir = svn_dirent_join(wcroot_abspath, ".svn/shelves", result_pool); /* Ensure the directory exists. (Other versions of svn don't create it.) */ SVN_ERR(svn_io_make_dir_recursively(*dir, scratch_pool));
