}
file_position relative_position(
- boost::string_ref::const_iterator begin,
- boost::string_ref::const_iterator iterator)
+ string_iterator begin,
+ string_iterator iterator)
{
file_position pos;
- boost::string_ref::const_iterator line_begin = begin;
+ string_iterator line_begin = begin;
while (begin != iterator)
{
return pos;
}
- file_position file::position_of(boost::string_ref::const_iterator iterator) const
+ file_position file::position_of(string_iterator iterator) const
{
return relative_position(source().begin(), iterator);
}
std::string::size_type our_pos;
section_types section_type;
- mapped_file_section(
- std::string::size_type original_pos,
- std::string::size_type our_pos,
- section_types section_type = normal) :
- original_pos(original_pos), our_pos(our_pos),
- section_type(section_type) {}
+ explicit mapped_file_section(
+ std::string::size_type original_pos_,
+ std::string::size_type our_pos_,
+ section_types section_type_ = normal) :
+ original_pos(original_pos_), our_pos(our_pos_),
+ section_type(section_type_) {}
};
struct mapped_section_original_cmp
struct mapped_file : file
{
- mapped_file(file_ptr original) :
- file(*original, std::string()),
- original(original), mapped_sections()
+ explicit mapped_file(file_ptr original_) :
+ file(*original_, std::string()),
+ original(original_), mapped_sections()
{}
file_ptr original;
std::vector<mapped_file_section> mapped_sections;
- void add_empty_mapped_file_section(boost::string_ref::const_iterator pos) {
+ void add_empty_mapped_file_section(string_iterator pos) {
std::string::size_type original_pos =
pos - original->source().begin();
}
}
- void add_mapped_file_section(boost::string_ref::const_iterator pos) {
+ void add_mapped_file_section(string_iterator pos) {
mapped_sections.push_back(mapped_file_section(
pos - original->source().begin(), source().size()));
}
- void add_indented_mapped_file_section(boost::string_ref::const_iterator pos)
+ void add_indented_mapped_file_section(string_iterator pos)
{
mapped_sections.push_back(mapped_file_section(
pos - original->source().begin(), source().size(),
case mapped_file_section::indented: {
// Will contain the start of the current line.
- boost::string_ref::size_type our_line = section->our_pos;
+ quickbook::string_view::size_type our_line = section->our_pos;
// Will contain the number of lines in the block before
// the current line.
unsigned newline_count = 0;
- for(boost::string_ref::size_type i = section->our_pos;
+ for(quickbook::string_view::size_type i = section->our_pos;
i != pos; ++i)
{
if (source()[i] == '\n') {
}
// The start of the line in the original source.
- boost::string_ref::size_type original_line =
+ quickbook::string_view::size_type original_line =
section->original_pos;
while(newline_count > 0) {
}
std::vector<mapped_file_section>::const_iterator find_section(
- boost::string_ref::const_iterator pos) const
+ string_iterator pos) const
{
std::vector<mapped_file_section>::const_iterator section =
boost::upper_bound(mapped_sections,
return section;
}
- virtual file_position position_of(boost::string_ref::const_iterator) const;
+ virtual file_position position_of(string_iterator) const;
private:
static std::string::size_type skip_indentation(
- boost::string_ref src, std::string::size_type i)
+ quickbook::string_view src, std::string::size_type i)
{
while (i != src.size() && (src[i] == ' ' || src[i] == '\t')) ++i;
return i;
return data->new_file->source().empty();
}
- mapped_file_builder::pos mapped_file_builder::get_pos() const
+ mapped_file_builder::pos_type mapped_file_builder::get_pos() const
{
return data->new_file->source().size();
}
- void mapped_file_builder::add_at_pos(boost::string_ref x, iterator pos)
+ void mapped_file_builder::add_at_pos(quickbook::string_view x, iterator pos)
{
data->new_file->add_empty_mapped_file_section(pos);
data->new_file->source_.append(x.begin(), x.end());
}
- void mapped_file_builder::add(boost::string_ref x)
+ void mapped_file_builder::add(quickbook::string_view x)
{
data->new_file->add_mapped_file_section(x.begin());
data->new_file->source_.append(x.begin(), x.end());
}
void mapped_file_builder::add(mapped_file_builder const& x,
- pos begin, pos end)
+ pos_type begin, pos_type end)
{
assert(data->new_file->original == x.data->new_file->original);
assert(begin <= x.data->new_file->source_.size());
if (begin != end)
{
- std::vector<mapped_file_section>::const_iterator start =
+ std::vector<mapped_file_section>::const_iterator i =
x.data->new_file->find_section(
x.data->new_file->source().begin() + begin);
std::string::size_type size = data->new_file->source_.size();
data->new_file->mapped_sections.push_back(mapped_file_section(
- x.data->new_file->to_original_pos(start, begin),
- size, start->section_type));
+ x.data->new_file->to_original_pos(i, begin),
+ size, i->section_type));
- for (++start; start != x.data->new_file->mapped_sections.end() &&
- start->our_pos < end; ++start)
+ for (++i; i != x.data->new_file->mapped_sections.end() &&
+ i->our_pos < end; ++i)
{
data->new_file->mapped_sections.push_back(mapped_file_section(
- start->original_pos, start->our_pos - begin + size,
- start->section_type));
+ i->original_pos, i->our_pos - begin + size,
+ i->section_type));
}
data->new_file->source_.append(
}
}
- boost::string_ref::size_type indentation_count(boost::string_ref x)
+ quickbook::string_view::size_type indentation_count(quickbook::string_view x)
{
unsigned count = 0;
- for(boost::string_ref::const_iterator begin = x.begin(), end = x.end();
+ for(string_iterator begin = x.begin(), end = x.end();
begin != end; ++begin)
{
switch(*begin)
return count;
}
- void mapped_file_builder::unindent_and_add(boost::string_ref x)
+ void mapped_file_builder::unindent_and_add(quickbook::string_view x)
{
// I wanted to do everything using a string_ref, but unfortunately
// they don't have all the overloads used in here. So...
std::string const program(x.begin(), x.end());
// Erase leading blank lines and newlines:
- std::string::size_type start = program.find_first_not_of(" \t\r\n");
- if (start == std::string::npos) return;
+ std::string::size_type text_start = program.find_first_not_of(" \t\r\n");
+ if (text_start == std::string::npos) return;
- start = program.find_last_of("\r\n", start);
- start = start == std::string::npos ? 0 : start + 1;
+ text_start = program.find_last_of("\r\n", text_start);
+ text_start = text_start == std::string::npos ? 0 : text_start + 1;
- assert(start < program.size());
+ assert(text_start < program.size());
// Get the first line indentation
- std::string::size_type indent = program.find_first_not_of(" \t", start) - start;
- boost::string_ref::size_type full_indent = indentation_count(
- boost::string_ref(&program[start], indent));
+ std::string::size_type indent = program.find_first_not_of(" \t", text_start) - text_start;
+ quickbook::string_view::size_type full_indent = indentation_count(
+ quickbook::string_view(&program[text_start], indent));
- std::string::size_type pos = start;
+ std::string::size_type pos = text_start;
// Calculate the minimum indent from the rest of the lines
// Detecting a mix of spaces and tabs.
indent = (std::min)(indent, n-pos);
full_indent = (std::min)(full_indent, indentation_count(
- boost::string_ref(&program[pos], n-pos)));
+ quickbook::string_view(&program[pos], n-pos)));
}
// Detect if indentation is mixed.
bool mixed_indentation = false;
- boost::string_ref first_indent(&program[start], indent);
- pos = start;
+ quickbook::string_view first_indent(&program[text_start], indent);
+ pos = text_start;
while (std::string::npos != (pos = program.find_first_of("\r\n", pos)))
{
std::string::size_type n = program.find_first_not_of(" \t", pos);
if (n == std::string::npos || n-pos < indent) continue;
- if (boost::string_ref(&program[pos], indent) != first_indent) {
+ if (quickbook::string_view(&program[pos], indent) != first_indent) {
mixed_indentation = true;
break;
}
// Trim white spaces from column 0..indent
std::string unindented_program;
- std::string::size_type copy_start = start;
- pos = start;
+ std::string::size_type copy_start = text_start;
+ pos = text_start;
do {
if (std::string::npos == (pos = program.find_first_not_of("\r\n", pos)))
if (mixed_indentation)
{
- unsigned length = indentation_count(boost::string_ref(
+ string_view::size_type length = indentation_count(quickbook::string_view(
&program[pos], next - pos));
if (length > full_indent) {
data->new_file->source_.append(unindented_program);
}
- file_position mapped_file::position_of(boost::string_ref::const_iterator pos) const
+ file_position mapped_file::position_of(string_iterator pos) const
{
return original->position_of(original->source().begin() +
to_original_pos(find_section(pos), pos - source().begin()));