Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRO-4107: [C++] Remove boost::algorithm #3284

Merged
merged 4 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lang/c++/impl/Compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <boost/algorithm/string/replace.hpp>

#include <sstream>
#include <unordered_set>
#include <utility>
Expand Down Expand Up @@ -136,7 +136,21 @@ int64_t getLongField(const Entity &e, const Object &m,
// Unescape double quotes (") for de-serialization. This method complements the
// method NodeImpl::escape() which is used for serialization.
wgtmac marked this conversation as resolved.
Show resolved Hide resolved
static void unescape(string &s) {
boost::replace_all(s, "\\\"", "\"");
size_t writePos = 0, readPos = 0;
while (readPos < s.length()) {
if (readPos + 1 < s.length() && s[readPos] == '\\' && s[readPos + 1] == '\"') {
s[writePos++] = '\"';
readPos += 2;
} else if (writePos != readPos) {
s[writePos++] = s[readPos++];
} else {
writePos++;
readPos++;
}
}
if (writePos != s.length()) {
s.resize(writePos);
}
}

string getDocField(const Entity &e, const Object &m) {
Expand Down
30 changes: 24 additions & 6 deletions lang/c++/impl/avrogencpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#endif
#include <fstream>
#include <iostream>
#include <locale>
#include <map>
#include <optional>
#include <random>
#include <set>
#include <utility>

#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>

#include "Compiler.hh"
Expand Down Expand Up @@ -741,9 +741,20 @@ void CodeGen::generateTraits(const NodePtr &n) {
void CodeGen::generateDocComment(const NodePtr &n, const char *indent) {
if (!n->getDoc().empty()) {
std::vector<std::string> lines;
boost::algorithm::split(lines, n->getDoc(), boost::algorithm::is_any_of("\n"));
{
const std::string &doc = n->getDoc();
size_t pos = 0;
size_t found;
while ((found = doc.find('\n', pos)) != std::string::npos) {
lines.push_back(doc.substr(pos, found - pos));
pos = found + 1;
}
if (pos < doc.size()) {
lines.push_back(doc.substr(pos));
}
}
for (auto &line : lines) {
boost::algorithm::replace_all(line, "\r", "");
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());

if (line.empty()) {
os_ << indent << "//\n";
Expand Down Expand Up @@ -859,12 +870,19 @@ static string readGuard(const string &filename) {
string buf;
string candidate;
while (std::getline(ifs, buf)) {
boost::algorithm::trim(buf);
if (!buf.empty()) {
size_t start = 0, end = buf.length();
while (start < end && std::isspace(buf[start], std::locale::classic())) start++;
while (start < end && std::isspace(buf[end - 1], std::locale::classic())) end--;
if (start > 0 || end < buf.length()) {
buf = buf.substr(start, end - start);
}
}
if (candidate.empty()) {
if (boost::algorithm::starts_with(buf, "#ifndef ")) {
if (buf.compare(0, 8, "#ifndef ") == 0) {
candidate = buf.substr(8);
}
} else if (boost::algorithm::starts_with(buf, "#define ")) {
} else if (buf.compare(0, 8, "#define ") == 0) {
if (candidate == buf.substr(8)) {
break;
}
Expand Down
Loading