Avoid using ctype's isalpha.

In general, ctype is local-dependent, and in MSVC isalpha asserts on non-ascii characters

PiperOrigin-RevId: 606696757
pull/15823/head
Mike Kruskal 10 months ago committed by Copybara-Service
parent c879718581
commit 4d3931d626
  1. 6
      src/google/protobuf/compiler/command_line_interface.cc
  2. 10
      src/google/protobuf/compiler/importer.cc
  3. 1
      src/google/protobuf/io/BUILD.bazel
  4. 4
      src/google/protobuf/io/io_win32.cc

@ -95,6 +95,10 @@
#include "google/protobuf/io/io_win32.h"
#endif
#if defined(_WIN32) || defined(__CYGWIN__)
#include "absl/strings/ascii.h"
#endif
// Must be included last.
#include "google/protobuf/port_def.inc"
@ -130,7 +134,7 @@ static const char* kDefaultDirectDependenciesViolationMsg =
// copy in importer.cc?
static bool IsWindowsAbsolutePath(const std::string& text) {
#if defined(_WIN32) || defined(__CYGWIN__)
return text.size() >= 3 && text[1] == ':' && isalpha(text[0]) &&
return text.size() >= 3 && text[1] == ':' && absl::ascii_isalpha(text[0]) &&
(text[2] == '/' || text[2] == '\\') && text.find_last_of(':') == 1;
#else
return false;

@ -36,10 +36,6 @@
#include "google/protobuf/io/tokenizer.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#ifdef _WIN32
#include <ctype.h>
#endif
namespace google {
namespace protobuf {
namespace compiler {
@ -51,12 +47,16 @@ using google::protobuf::io::win32::access;
using google::protobuf::io::win32::open;
#endif
#if defined(_WIN32) || defined(__CYGWIN__)
#include "absl/strings/ascii.h"
#endif
// Returns true if the text looks like a Windows-style absolute path, starting
// with a drive letter. Example: "C:\foo". TODO: Share this with
// copy in command_line_interface.cc?
static bool IsWindowsAbsolutePath(absl::string_view text) {
#if defined(_WIN32) || defined(__CYGWIN__)
return text.size() >= 3 && text[1] == ':' && isalpha(text[0]) &&
return text.size() >= 3 && text[1] == ':' && absl::ascii_isalpha(text[0]) &&
(text[2] == '/' || text[2] == '\\') && text.find_last_of(':') == 1;
#else
return false;

@ -177,6 +177,7 @@ cc_library(
deps = [
"//src/google/protobuf:arena",
"//src/google/protobuf/stubs:lite",
"@com_google_absl//absl/strings",
],
)

@ -37,6 +37,8 @@
#include <sys/types.h>
#include <wctype.h>
#include "absl/strings/ascii.h"
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
@ -64,7 +66,7 @@ struct CharTraits {
template <>
struct CharTraits<char> {
static bool is_alpha(char ch) { return isalpha(ch); }
static bool is_alpha(char ch) { return absl::ascii_isalpha(ch); }
};
template <>

Loading…
Cancel
Save