MCPcopy Create free account
hub / github.com/davisking/dlib / format_comment

Function format_comment

tools/htmlify/to_xml.cpp:1139–1223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1137// ----------------------------------------------------------------------------------------
1138
1139string format_comment (
1140 const string& comment,
1141 const unsigned long expand_tabs
1142)
1143{
1144 if (comment.size() <= 6)
1145 return "";
1146
1147 string temp = trim(trim(comment.substr(3,comment.size()-6), " \t"), "\n\r");
1148
1149
1150 // if we should expand tabs to spaces
1151 if (expand_tabs != 0)
1152 {
1153 unsigned long column = 0;
1154 string str;
1155 for (unsigned long i = 0; i < temp.size(); ++i)
1156 {
1157 if (temp[i] == '\t')
1158 {
1159 const unsigned long num_spaces = expand_tabs - column%expand_tabs;
1160 column += num_spaces;
1161 str.insert(str.end(), num_spaces, ' ');
1162 }
1163 else if (temp[i] == '\n' || temp[i] == '\r')
1164 {
1165 str += temp[i];
1166 column = 0;
1167 }
1168 else
1169 {
1170 str += temp[i];
1171 ++column;
1172 }
1173 }
1174
1175 // put str into temp
1176 str.swap(temp);
1177 }
1178
1179 // now figure out what the smallest amount of leading white space is and remove it from each line.
1180 unsigned long num_whitespace = 100000;
1181
1182 string::size_type pos1 = 0, pos2 = 0;
1183
1184 while (pos1 != string::npos)
1185 {
1186 // find start of non-white-space
1187 pos2 = temp.find_first_not_of(" \t",pos1);
1188
1189 // if this is a line of just white space then ignore it
1190 if (pos2 != string::npos && temp[pos2] != '\n' && temp[pos2] != '\r')
1191 {
1192 if (pos2-pos1 < num_whitespace)
1193 num_whitespace = pos2-pos1;
1194 }
1195
1196 // find end-of-line

Callers 3

convert_tok_class_recordFunction · 0.85

Calls 5

trimFunction · 0.85
sizeMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
swapMethod · 0.45

Tested by

no test coverage detected