2020-02-28 03:50:58 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2020-04-18 03:39:50 -05:00
|
|
|
#pragma once
|
2020-02-28 03:50:58 -06:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-02-28 07:51:22 -06:00
|
|
|
/**
|
|
|
|
* Stores an offset and a length into the single underlying string of StringVector.
|
|
|
|
*/
|
|
|
|
struct StringToken
|
|
|
|
{
|
|
|
|
size_t _index;
|
|
|
|
size_t _length;
|
|
|
|
|
|
|
|
StringToken() = default;
|
|
|
|
|
|
|
|
StringToken(size_t index, size_t length)
|
|
|
|
: _index(index),
|
|
|
|
_length(length)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-28 03:50:58 -06:00
|
|
|
/**
|
|
|
|
* Safe wrapper around an std::vector<std::string>. Gives you an empty string if you would read past
|
|
|
|
* the ends of the vector.
|
|
|
|
*/
|
|
|
|
class StringVector
|
|
|
|
{
|
2020-02-28 07:51:22 -06:00
|
|
|
/// All tokens are substrings of this string.
|
|
|
|
std::string _string;
|
|
|
|
std::vector<StringToken> _tokens;
|
2020-02-28 03:50:58 -06:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit StringVector();
|
|
|
|
|
2020-02-28 07:51:22 -06:00
|
|
|
explicit StringVector(const std::string& string, const std::vector<StringToken>& tokens);
|
2020-02-28 03:50:58 -06:00
|
|
|
|
|
|
|
/// Unlike std::vector, gives an empty string if index is unexpected.
|
|
|
|
std::string operator[](size_t index) const;
|
|
|
|
|
|
|
|
size_t size() const;
|
|
|
|
|
|
|
|
bool empty() const;
|
|
|
|
|
2020-02-28 07:51:22 -06:00
|
|
|
std::vector<StringToken>::const_iterator begin() const;
|
2020-02-28 03:50:58 -06:00
|
|
|
|
2020-02-28 07:51:22 -06:00
|
|
|
std::vector<StringToken>::iterator begin();
|
2020-02-28 03:50:58 -06:00
|
|
|
|
2020-02-28 07:51:22 -06:00
|
|
|
std::vector<StringToken>::const_iterator end() const;
|
2020-02-28 03:50:58 -06:00
|
|
|
|
2020-02-28 07:51:22 -06:00
|
|
|
std::vector<StringToken>::iterator end();
|
2020-02-28 03:50:58 -06:00
|
|
|
|
2020-02-28 07:51:22 -06:00
|
|
|
std::vector<StringToken>::iterator erase(std::vector<StringToken>::const_iterator it);
|
2020-02-28 03:50:58 -06:00
|
|
|
|
|
|
|
void push_back(const std::string& string);
|
2020-02-28 07:51:22 -06:00
|
|
|
|
|
|
|
/// Gets the underlying string of a single token.
|
|
|
|
std::string getParam(const StringToken& token) const;
|
|
|
|
|
|
|
|
/// Concats tokens starting from begin, using separator as separator.
|
|
|
|
std::string cat(const std::string& separator, size_t begin) const;
|
2020-03-09 03:05:30 -05:00
|
|
|
|
|
|
|
/// Compares the nth token with string.
|
|
|
|
bool equals(size_t index, const char* string) const;
|
|
|
|
|
|
|
|
/// Compares the nth token with the mth token from an other StringVector.
|
|
|
|
bool equals(size_t index, const StringVector& other, size_t otherIndex);
|
2020-02-28 03:50:58 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|