Google OR-Tools
v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
lp_name.cc
Go to the documentation of this file.
1
// Copyright 2010-2025 Google LLC
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13
14
#include "
ortools/math_opt/io/lp/lp_name.h
"
15
16
#include "absl/status/status.h"
17
#include "absl/strings/ascii.h"
18
#include "absl/strings/string_view.h"
19
#include "
ortools/base/status_builder.h
"
20
21
namespace
operations_research::lp_format
{
22
23
bool
ValidateCharInName
(
unsigned
char
c,
bool
leading) {
24
if
(absl::ascii_isalpha(c)) {
25
return
true
;
26
}
27
if
(!leading) {
28
if
(c ==
'.'
|| absl::ascii_isdigit(c)) {
29
return
true
;
30
}
31
}
32
switch
(c) {
33
case
'!'
:
34
case
'"'
:
35
case
'#'
:
36
case
'$'
:
37
case
'%'
:
38
case
'&'
:
39
case
'('
:
40
case
')'
:
41
case
','
:
42
case
';'
:
43
case
'?'
:
44
case
'@'
:
45
case
'_'
:
46
case
'`'
:
47
case
'\''
:
48
case
'{'
:
49
case
'}'
:
50
case
'~'
:
51
return
true
;
52
default
:
53
return
false
;
54
}
55
}
56
57
absl::Status
ValidateName
(absl::string_view name) {
58
if
(name.empty()) {
59
return
absl::InvalidArgumentError(
"empty name invalid"
);
60
}
61
for
(
int
i = 0; i < name.size(); ++i) {
62
if
(!
ValidateCharInName
(name[i], i == 0)) {
63
return
util::InvalidArgumentErrorBuilder
()
64
<<
"invalid character: "
<< name[i] <<
" at index: "
<< i
65
<<
" in: "
<< name;
66
}
67
}
68
return
absl::OkStatus();
69
}
70
71
}
// namespace operations_research::lp_format
lp_name.h
operations_research::lp_format
Definition
lp_model.cc:32
operations_research::lp_format::ValidateName
absl::Status ValidateName(absl::string_view name)
Definition
lp_name.cc:57
operations_research::lp_format::ValidateCharInName
bool ValidateCharInName(unsigned char c, bool leading)
Definition
lp_name.cc:23
util::InvalidArgumentErrorBuilder
StatusBuilder InvalidArgumentErrorBuilder()
Definition
status_builder.h:107
status_builder.h
ortools
math_opt
io
lp
lp_name.cc
Generated by
1.15.0