MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / ShortenMsg

Function ShortenMsg

oneflow/core/common/error_util.cpp:38–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38Maybe<std::string> ShortenMsg(std::string str) {
39 // 150 characters is the threshold
40 const int num_character_threshold = 150;
41 const int num_displayed_character = 50;
42 if (str.size() == 0) { return str; }
43 // strip space when JUST( xx );
44 str = StripSpace(str);
45 if (str.size() < num_character_threshold) { return str; }
46
47 // left part whose number of characters is just over 50
48 int left_index = num_displayed_character;
49 bool pre_condition = IsLetterNumberOrUnderline(str.at(left_index));
50 for (; left_index < str.size(); left_index++) {
51 bool cur_condition = IsLetterNumberOrUnderline(str.at(left_index));
52 if ((pre_condition && !cur_condition) || (!pre_condition && cur_condition)) { break; }
53 }
54
55 // right part whose number of characters is just over 50
56 int right_index = str.size() - num_displayed_character;
57 pre_condition = IsLetterNumberOrUnderline(str.at(right_index));
58 for (; right_index >= 0; right_index--) {
59 bool cur_condition = IsLetterNumberOrUnderline(str.at(right_index));
60 if ((pre_condition && !cur_condition) || (!pre_condition && cur_condition)) {
61 right_index++;
62 break;
63 }
64 }
65 // a long word of more than 150
66 if (right_index - left_index < 50) { return str; }
67 std::stringstream ss;
68 CHECK_OR_RETURN(left_index >= 0);
69 CHECK_OR_RETURN(left_index < str.size());
70 ss << str.substr(0, left_index);
71 ss << " ... ";
72 CHECK_OR_RETURN(right_index >= 0);
73 CHECK_OR_RETURN(right_index < str.size());
74 ss << str.substr(right_index);
75 return ss.str();
76}
77
78// file info in stack frame
79std::string FormatFileOfStackFrame(const std::string& file) {

Callers 1

FormatMsgOfStackFrameFunction · 0.85

Calls 4

StripSpaceFunction · 0.85
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected