Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
strings Namespace Reference

#include "ortools/base/logging.h" More...

Classes

struct  AsciiCaseInsensitiveEq
 
struct  AsciiCaseInsensitiveHash
 
struct  AsciiCaseInsensitiveLess
 

Enumerations

enum class  AsciiCapitalizationType {
  kLower , kUpper , kFirst , kMixed ,
  kNoAlpha
}
 Enum values returned by GetAsciiCapitalization(). More...
 

Functions

std::ostream & operator<< (std::ostream &os, const AsciiCapitalizationType &type)
 Prints the name of an enum value.
 
AsciiCapitalizationType GetAsciiCapitalization (const absl::string_view input)
 
int AsciiCaseInsensitiveCompare (absl::string_view s1, absl::string_view s2)
 
void MakeAsciiTitlecase (std::string *s, absl::string_view delimiters)
 
std::string MakeAsciiTitlecase (absl::string_view s, absl::string_view delimiters)
 As above but with string_view as input.
 
int64_t strtoint64 (const char *nptr, char **endptr, int base)
 
uint64_t strtouint64 (const char *nptr, char **endptr, int base)
 
int32_t strtoint32 (const char *nptr, char **endptr, int base)
 
uint32_t strtouint32 (const char *nptr, char **endptr, int base)
 
int32_t ParseLeadingInt32Value (const char *str, int32_t deflt)
 
uint32_t ParseLeadingUInt32Value (const char *str, uint32_t deflt)
 
int32_t ParseLeadingDec32Value (const char *str, int32_t deflt)
 
uint32_t ParseLeadingUDec32Value (const char *str, uint32_t deflt)
 
uint64_t ParseLeadingUInt64Value (const char *str, uint64_t deflt)
 
int64_t ParseLeadingInt64Value (const char *str, int64_t deflt)
 
uint64_t ParseLeadingHex64Value (const char *str, uint64_t deflt)
 
int64_t ParseLeadingDec64Value (const char *str, int64_t deflt)
 
uint64_t ParseLeadingUDec64Value (const char *str, uint64_t deflt)
 
double ParseLeadingDoubleValue (const char *str, double deflt)
 
false no n y bool ParseLeadingBoolValue (const char *str, bool deflt)
 
int32_t ParseLeadingInt32Value (std::string_view str, int32_t deflt)
 
uint32_t ParseLeadingUInt32Value (std::string_view str, uint32_t deflt)
 
int32_t ParseLeadingDec32Value (std::string_view str, int32_t deflt)
 
uint32_t ParseLeadingUDec32Value (std::string_view str, uint32_t deflt)
 
uint64_t ParseLeadingUInt64Value (std::string_view str, uint64_t deflt)
 
int64_t ParseLeadingInt64Value (std::string_view str, int64_t deflt)
 
uint64_t ParseLeadingHex64Value (std::string_view str, uint64_t deflt)
 
int64_t ParseLeadingDec64Value (std::string_view str, int64_t deflt)
 
uint64_t ParseLeadingUDec64Value (std::string_view str, uint64_t deflt)
 
double ParseLeadingDoubleValue (std::string_view str, double deflt)
 
bool ParseLeadingBoolValue (std::string_view str, bool deflt)
 

Variables

false true
 
false no yes
 

Detailed Description

#include "ortools/base/logging.h"

Convert strings to numbers or numbers to strings.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This file contains string processing functions related to uppercase, lowercase, etc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This package contains character classification functions for evaluating the case state of strings, and converting strings to uppercase, lowercase, etc.

Unlike <ctype.h> (or absl/strings/ascii.h), the functions in this file are designed to operate on strings, not single characters.

Except for those marked as "using the C/POSIX locale", these functions are for ASCII strings only.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This file contains std::string processing functions related to numeric values.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Enumeration Type Documentation

◆ AsciiCapitalizationType

Enum values returned by GetAsciiCapitalization().

Enumerator
kLower 
kUpper 
kFirst 
kMixed 
kNoAlpha 

Definition at line 45 of file case.h.

Function Documentation

◆ AsciiCaseInsensitiveCompare()

int strings::AsciiCaseInsensitiveCompare ( absl::string_view s1,
absl::string_view s2 )

AsciiCaseInsensitiveCompare()

Performs a case-insensitive absl::string_view comparison. Returns: less than 0: if s1 < s2 equal to 0: if s1 == s2 greater than 0: if s1 > s2

Definition at line 90 of file case.cc.

◆ GetAsciiCapitalization()

AsciiCapitalizationType strings::GetAsciiCapitalization ( absl::string_view input)

GetAsciiCapitalization()

Returns a value indicating whether an ASCII string is entirely lowercase, entirely uppercase, first letter uppercase, or mixed case, as returned by absl::ascii_islower() and absl::ascii_isupper().

find the caps type of the first alpha char

skip ahead to the next alpha char

Definition at line 52 of file case.cc.

◆ MakeAsciiTitlecase() [1/2]

std::string strings::MakeAsciiTitlecase ( absl::string_view s,
absl::string_view delimiters )

As above but with string_view as input.

Definition at line 123 of file case.cc.

◆ MakeAsciiTitlecase() [2/2]

void strings::MakeAsciiTitlecase ( std::string * s,
absl::string_view delimiters )

MakeAsciiTitlecase()

Capitalizes the first character of each word in a string, using the set of characters in delimiters to use as word boundaries. This function can be implemented using a regular expression, but this version should be more efficient.

Definition at line 113 of file case.cc.

◆ operator<<()

std::ostream & strings::operator<< ( std::ostream & os,
const AsciiCapitalizationType & type )

Prints the name of an enum value.

Definition at line 34 of file case.cc.

◆ ParseLeadingBoolValue() [1/2]

false no n y bool strings::ParseLeadingBoolValue ( const char * str,
bool deflt )

Skip whitespace

Definition at line 231 of file numbers.cc.

◆ ParseLeadingBoolValue() [2/2]

bool strings::ParseLeadingBoolValue ( std::string_view str,
bool deflt )
inline

Definition at line 141 of file numbers.h.

◆ ParseLeadingDec32Value() [1/2]

int32_t strings::ParseLeadingDec32Value ( const char * str,
int32_t deflt )

ParseLeadingDec32Value ParseLeadingUDec32Value A simple parser for [u]int32_t values. Returns the parsed value if a valid value is found; else returns deflt The std::string passed in is treated as 10 based. This can handle strings with leading 0s.

ParseLeadingDec32Value A simple parser for decimal int32_t values. Returns the parsed value if a valid integer is found; else returns deflt. It does not check if str is entirely consumed. The std::string passed in is treated as 10 based. This can handle strings with leading 0s. See also: ParseLeadingDec64Value

Limit long values to int32_t min/max. Needed for lp64; no-op on 32 bits.

Definition at line 111 of file numbers.cc.

◆ ParseLeadingDec32Value() [2/2]

int32_t strings::ParseLeadingDec32Value ( std::string_view str,
int32_t deflt )
inline

Definition at line 67 of file numbers.h.

◆ ParseLeadingDec64Value() [1/2]

int64_t strings::ParseLeadingDec64Value ( const char * str,
int64_t deflt )

ParseLeadingDec64Value ParseLeadingUDec64Value A simple parser for [u]int64_t values. Returns the parsed value if a valid value is found; else returns deflt The std::string passed in is treated as 10 based. This can handle strings with leading 0s.

Definition at line 190 of file numbers.cc.

◆ ParseLeadingDec64Value() [2/2]

int64_t strings::ParseLeadingDec64Value ( std::string_view str,
int64_t deflt )
inline

Definition at line 110 of file numbers.h.

◆ ParseLeadingDoubleValue() [1/2]

double strings::ParseLeadingDoubleValue ( const char * str,
double deflt )

ParseLeadingDoubleValue() A simple parser for double values. Returns the parsed value if a valid value is found; else returns deflt

ParseLeadingDoubleValue A simple parser for double values. Returns the parsed value if a valid double is found; else returns deflt. It does not check if str is entirely consumed.

Definition at line 210 of file numbers.cc.

◆ ParseLeadingDoubleValue() [2/2]

double strings::ParseLeadingDoubleValue ( std::string_view str,
double deflt )
inline

Definition at line 127 of file numbers.h.

◆ ParseLeadingHex64Value() [1/2]

uint64_t strings::ParseLeadingHex64Value ( const char * str,
uint64_t deflt )

Definition at line 173 of file numbers.cc.

◆ ParseLeadingHex64Value() [2/2]

uint64_t strings::ParseLeadingHex64Value ( std::string_view str,
uint64_t deflt )
inline

Definition at line 106 of file numbers.h.

◆ ParseLeadingInt32Value() [1/2]

int32_t strings::ParseLeadingInt32Value ( const char * str,
int32_t deflt )

ParseLeadingInt32Value() ParseLeadingUInt32Value() A simple parser for [u]int32_t values. Returns the parsed value if a valid value is found; else returns deflt This cannot handle decimal numbers with leading 0s.

ParseLeadingInt32Value A simple parser for int32_t values. Returns the parsed value if a valid integer is found; else returns deflt. It does not check if str is entirely consumed. This cannot handle decimal numbers with leading 0s, since they will be treated as octal. If you know it's decimal, use ParseLeadingDec32Value.

Limit long values to int32_t min/max. Needed for lp64; no-op on 32 bits.

Definition at line 60 of file numbers.cc.

◆ ParseLeadingInt32Value() [2/2]

int32_t strings::ParseLeadingInt32Value ( std::string_view str,
int32_t deflt )
inline

Definition at line 38 of file numbers.h.

◆ ParseLeadingInt64Value() [1/2]

int64_t strings::ParseLeadingInt64Value ( const char * str,
int64_t deflt )

Definition at line 167 of file numbers.cc.

◆ ParseLeadingInt64Value() [2/2]

int64_t strings::ParseLeadingInt64Value ( std::string_view str,
int64_t deflt )
inline

Definition at line 102 of file numbers.h.

◆ ParseLeadingUDec32Value() [1/2]

uint32_t strings::ParseLeadingUDec32Value ( const char * str,
uint32_t deflt )

ParseLeadingUDec32Value A simple parser for decimal uint32_t values. Returns the parsed value if a valid integer is found; else returns deflt. It does not check if str is entirely consumed. The std::string passed in is treated as 10 based. This can handle strings with leading 0s. See also: ParseLeadingUDec64Value

When long is 32 bits, we can use strtoul.

When long is 64 bits, we must use strtoint64 and handle limits by hand. The reason we cannot use a 64-bit strtoul is that it would be impossible to differentiate "-2" (that should wrap around to the value UINT_MAX-1) from a std::string with ULONG_MAX-1 (that should be pegged to UINT_MAX due to overflow).

Within these limits, truncation to 32 bits handles negatives correctly.

Definition at line 125 of file numbers.cc.

◆ ParseLeadingUDec32Value() [2/2]

uint32_t strings::ParseLeadingUDec32Value ( std::string_view str,
uint32_t deflt )
inline

Definition at line 81 of file numbers.h.

◆ ParseLeadingUDec64Value() [1/2]

uint64_t strings::ParseLeadingUDec64Value ( const char * str,
uint64_t deflt )

Definition at line 196 of file numbers.cc.

◆ ParseLeadingUDec64Value() [2/2]

uint64_t strings::ParseLeadingUDec64Value ( std::string_view str,
uint64_t deflt )
inline

Definition at line 114 of file numbers.h.

◆ ParseLeadingUInt32Value() [1/2]

uint32_t strings::ParseLeadingUInt32Value ( const char * str,
uint32_t deflt )

ParseLeadingUInt32Value A simple parser for uint32_t values. Returns the parsed value if a valid integer is found; else returns deflt. It does not check if str is entirely consumed. This cannot handle decimal numbers with leading 0s, since they will be treated as octal. If you know it's decimal, use ParseLeadingUDec32Value.

When long is 32 bits, we can use strtoul.

When long is 64 bits, we must use strtoint64 and handle limits by hand. The reason we cannot use a 64-bit strtoul is that it would be impossible to differentiate "-2" (that should wrap around to the value UINT_MAX-1) from a std::string with ULONG_MAX-1 (that should be pegged to UINT_MAX due to overflow).

Within these limits, truncation to 32 bits handles negatives correctly.

Definition at line 74 of file numbers.cc.

◆ ParseLeadingUInt32Value() [2/2]

uint32_t strings::ParseLeadingUInt32Value ( std::string_view str,
uint32_t deflt )
inline

Definition at line 51 of file numbers.h.

◆ ParseLeadingUInt64Value() [1/2]

uint64_t strings::ParseLeadingUInt64Value ( const char * str,
uint64_t deflt )

ParseLeadingUInt64Value ParseLeadingInt64Value ParseLeadingHex64Value A simple parser for 64-bit values. Returns the parsed value if a valid integer is found; else returns deflt Uint64_t and int64_t cannot handle decimal numbers with leading 0s.

ParseLeadingUInt64Value ParseLeadingInt64Value ParseLeadingHex64Value ParseLeadingDec64Value ParseLeadingUDec64Value A simple parser for long long values. Returns the parsed value if a valid integer is found; else returns deflt

Definition at line 161 of file numbers.cc.

◆ ParseLeadingUInt64Value() [2/2]

uint64_t strings::ParseLeadingUInt64Value ( std::string_view str,
uint64_t deflt )
inline

Definition at line 98 of file numbers.h.

◆ strtoint32()

int32_t strings::strtoint32 ( const char * nptr,
char ** endptr,
int base )
inline

Definition at line 42 of file numbers.cc.

◆ strtoint64()

int64_t strings::strtoint64 ( const char * nptr,
char ** endptr,
int base )
inline

Definition at line 34 of file numbers.cc.

◆ strtouint32()

uint32_t strings::strtouint32 ( const char * nptr,
char ** endptr,
int base )
inline

Definition at line 46 of file numbers.cc.

◆ strtouint64()

uint64_t strings::strtouint64 ( const char * nptr,
char ** endptr,
int base )
inline

Definition at line 38 of file numbers.cc.

Variable Documentation

◆ true

false strings::true

Definition at line 228 of file numbers.cc.

◆ yes

false no strings::yes

Definition at line 228 of file numbers.cc.