-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathcpp_blob.cpp
More file actions
46 lines (36 loc) · 726 Bytes
/
Copy pathcpp_blob.cpp
File metadata and controls
46 lines (36 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (C) 2022 Satya Das and CppParser contributors
// SPDX-License-Identifier: MIT
#include "cppast/cpp_blob.h"
namespace cppast {
namespace {
/**
* @brief Trims traling spaces and leading empty lines.
*/
std::string& TrimBlob(std::string& s)
{
auto len = s.size();
for (; len > 0; --len)
{
if (!isspace(s[len - 1]))
break;
}
s.resize(len);
size_t start = 0;
for (size_t i = 0; i < s.size(); ++i)
{
if (!isspace(s[i]))
break;
if (s[i] == '\n')
start = i + 1;
}
if (start > 0)
s = s.substr(start);
return s;
}
} // namespace
CppBlob::CppBlob(std::string blob)
: CppEntity(EntityType())
, blob_(std::move(TrimBlob(blob)))
{
}
} // namespace cppast