From 19b03021545ec0a86e8bdc0df8c8c20e2cea90e6 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 3 Apr 2024 23:58:13 +0200 Subject: [PATCH] Add non-locale aware CPLTolower() and CPLToupper() --- port/cpl_string.cpp | 30 ++++++++++++++++++++++++++++++ port/cpl_string.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/port/cpl_string.cpp b/port/cpl_string.cpp index bbdddb651063..f7372c29f7cd 100644 --- a/port/cpl_string.cpp +++ b/port/cpl_string.cpp @@ -3021,3 +3021,33 @@ char **CSLParseCommandLine(const char *pszCommandLine) { return CSLTokenizeString(pszCommandLine); } + +/************************************************************************/ +/* CPLToupper() */ +/************************************************************************/ + +/** Converts a (ASCII) lowercase character to uppercase. + * + * Same as standard toupper(), except that it is not locale sensitive. + * + * @since GDAL 3.9 + */ +int CPLToupper(int c) +{ + return (c >= 'a' && c <= 'z') ? (c - 'a' + 'A') : c; +} + +/************************************************************************/ +/* CPLTolower() */ +/************************************************************************/ + +/** Converts a (ASCII) uppercase character to lowercase. + * + * Same as standard tolower(), except that it is not locale sensitive. + * + * @since GDAL 3.9 + */ +int CPLTolower(int c) +{ + return (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; +} diff --git a/port/cpl_string.h b/port/cpl_string.h index cf577d46901b..f666bab9ab2c 100644 --- a/port/cpl_string.h +++ b/port/cpl_string.h @@ -190,6 +190,9 @@ typedef enum CPLValueType CPL_DLL CPLGetValueType(const char *pszValue); +int CPL_DLL CPLToupper(int c); +int CPL_DLL CPLTolower(int c); + size_t CPL_DLL CPLStrlcpy(char *pszDest, const char *pszSrc, size_t nDestSize); size_t CPL_DLL CPLStrlcat(char *pszDest, const char *pszSrc, size_t nDestSize); size_t CPL_DLL CPLStrnlen(const char *pszStr, size_t nMaxLen);