Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
string_util.h
Go to the documentation of this file.
1// Copyright 2010-2024 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#ifndef OR_TOOLS_UTIL_STRING_UTIL_H_
15#define OR_TOOLS_UTIL_STRING_UTIL_H_
16
17#include <string>
18
19#include "absl/strings/str_cat.h"
20
21namespace operations_research {
22
23// Crops a multi-line string horizontally and vertically, as needed. Skipped
24// lines (to spare vertical space) are replaced by "... [42 LINES CROPPED] ..."
25// and non-skipped but cropped lines (to spare horizontal space) are replaced
26// by "%prefix% ..[35 CHARS CROPPED].. %suffix%" where %prefix% and %suffix% are
27// equally-sized (possibly off-by-one) substrings of the line, to fit in the
28// required width.
29//
30// WARNING: The code is intended to be used for debugging and visual aid.
31// While it shouldn't crash, it makes a few shortcuts and can violate the
32// requirements (eg. some lines may be longer than max_line_length).
33std::string CropMultiLineString(const std::string& s, int max_line_length,
34 int max_num_lines);
35
36// Helper to display a object with a DebugString method in a absl::StrJoin.
38 template <typename T>
39 void operator()(std::string* out, const T& t) const {
40 absl::StrAppend(out, t.DebugString());
41 }
42};
43
44} // namespace operations_research
45
46#endif // OR_TOOLS_UTIL_STRING_UTIL_H_
In SWIG mode, we don't want anything besides these top-level includes.
std::string CropMultiLineString(const std::string &s, int max_line_length, int max_num_lines)
Helper to display a object with a DebugString method in a absl::StrJoin.
Definition string_util.h:37
void operator()(std::string *out, const T &t) const
Definition string_util.h:39