本文整理汇总了C++中SourceColumnMap::columnToByte方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceColumnMap::columnToByte方法的具体用法?C++ SourceColumnMap::columnToByte怎么用?C++ SourceColumnMap::columnToByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceColumnMap
的用法示例。
在下文中一共展示了SourceColumnMap::columnToByte方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: selectInterestingSourceRegion
/// \brief When the source code line we want to print is too long for
/// the terminal, select the "interesting" region.
static void selectInterestingSourceRegion(std::string &SourceLine,
std::string &CaretLine,
std::string &FixItInsertionLine,
unsigned Columns,
const SourceColumnMap &map) {
unsigned MaxColumns = std::max<unsigned>(map.columns(),
std::max(CaretLine.size(),
FixItInsertionLine.size()));
// if the number of columns is less than the desired number we're done
if (MaxColumns <= Columns)
return;
// no special characters allowed in CaretLine or FixItInsertionLine
assert(CaretLine.end() ==
std::find_if(CaretLine.begin(), CaretLine.end(),
char_out_of_range(' ','~')));
assert(FixItInsertionLine.end() ==
std::find_if(FixItInsertionLine.begin(), FixItInsertionLine.end(),
char_out_of_range(' ','~')));
// Find the slice that we need to display the full caret line
// correctly.
unsigned CaretStart = 0, CaretEnd = CaretLine.size();
for (; CaretStart != CaretEnd; ++CaretStart)
if (!isspace(static_cast<unsigned char>(CaretLine[CaretStart])))
break;
for (; CaretEnd != CaretStart; --CaretEnd)
if (!isspace(static_cast<unsigned char>(CaretLine[CaretEnd - 1])))
break;
// caret has already been inserted into CaretLine so the above whitespace
// check is guaranteed to include the caret
// If we have a fix-it line, make sure the slice includes all of the
// fix-it information.
if (!FixItInsertionLine.empty()) {
unsigned FixItStart = 0, FixItEnd = FixItInsertionLine.size();
for (; FixItStart != FixItEnd; ++FixItStart)
if (!isspace(static_cast<unsigned char>(FixItInsertionLine[FixItStart])))
break;
for (; FixItEnd != FixItStart; --FixItEnd)
if (!isspace(static_cast<unsigned char>(FixItInsertionLine[FixItEnd - 1])))
break;
CaretStart = std::min(FixItStart, CaretStart);
CaretEnd = std::max(FixItEnd, CaretEnd);
}
// CaretEnd may have been set at the middle of a character
// If it's not at a character's first column then advance it past the current
// character.
while (static_cast<int>(CaretEnd) < map.columns() &&
-1 == map.columnToByte(CaretEnd))
++CaretEnd;
assert((static_cast<int>(CaretStart) > map.columns() ||
-1!=map.columnToByte(CaretStart)) &&
"CaretStart must not point to a column in the middle of a source"
" line character");
assert((static_cast<int>(CaretEnd) > map.columns() ||
-1!=map.columnToByte(CaretEnd)) &&
"CaretEnd must not point to a column in the middle of a source line"
" character");
// CaretLine[CaretStart, CaretEnd) contains all of the interesting
// parts of the caret line. While this slice is smaller than the
// number of columns we have, try to grow the slice to encompass
// more context.
unsigned SourceStart = map.columnToByte(std::min<unsigned>(CaretStart,
map.columns()));
unsigned SourceEnd = map.columnToByte(std::min<unsigned>(CaretEnd,
map.columns()));
unsigned CaretColumnsOutsideSource = CaretEnd-CaretStart
- (map.byteToColumn(SourceEnd)-map.byteToColumn(SourceStart));
char const *front_ellipse = " ...";
char const *front_space = " ";
char const *back_ellipse = "...";
unsigned ellipses_space = strlen(front_ellipse) + strlen(back_ellipse);
unsigned TargetColumns = Columns;
// Give us extra room for the ellipses
// and any of the caret line that extends past the source
if (TargetColumns > ellipses_space+CaretColumnsOutsideSource)
TargetColumns -= ellipses_space+CaretColumnsOutsideSource;
while (SourceStart>0 || SourceEnd<SourceLine.size()) {
bool ExpandedRegion = false;
if (SourceStart>0) {
unsigned NewStart = map.startOfPreviousColumn(SourceStart);
// Skip over any whitespace we see here; we're looking for
// another bit of interesting text.
//.........这里部分代码省略.........