Skip to content

Commit 7395b5d

Browse files
committed
vendored boost/regex.hpp is now a private dependency
- Do not include boost/regex.hpp in the main api file (TextEditor.h), so that users do not need to add vendor/boost/regex to their include path - Only TextEditor.cpp will include boost/regex.hpp (private dependency) - We use a partial pImpl: RegexList is declared inside TextEditor.h, and implemented inside TextEditor.cpp - We use a shared_ptr<RegexList> instead of unique_ptr , because we want to keep TextEditor copyable (otherwise, this would break the API for existing users)
1 parent 74fcc63 commit 7395b5d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

TextEditor.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <algorithm>
22
#include <string>
33
#include <set>
4+
#include <boost/regex.hpp>
45

56
#include "TextEditor.h"
67

@@ -9,10 +10,17 @@
910
#define IMGUI_DEFINE_MATH_OPERATORS
1011
#include "imgui.h" // for imGui::GetCurrentWindow()
1112

13+
14+
struct TextEditor::RegexList {
15+
std::vector<std::pair<boost::regex, TextEditor::PaletteIndex>> mValue;
16+
};
17+
18+
1219
// --------------------------------------- //
1320
// ------------- Exposed API ------------- //
1421

1522
TextEditor::TextEditor()
23+
: mRegexList(std::make_shared<RegexList>())
1624
{
1725
SetPalette(defaultPalette);
1826
mLines.push_back(Line());
@@ -90,9 +98,9 @@ void TextEditor::SetLanguageDefinition(LanguageDefinitionId aValue)
9098
break;
9199
}
92100

93-
mRegexList.clear();
101+
mRegexList->mValue.clear();
94102
for (const auto& r : mLanguageDefinition->mTokenRegexStrings)
95-
mRegexList.push_back(std::make_pair(boost::regex(r.first, boost::regex_constants::optimize), r.second));
103+
mRegexList->mValue.push_back(std::make_pair(boost::regex(r.first, boost::regex_constants::optimize), r.second));
96104

97105
Colorize();
98106
}
@@ -2630,7 +2638,7 @@ void TextEditor::ColorizeRange(int aFromLine, int aToLine)
26302638
// todo : remove
26312639
//printf("using regex for %.*s\n", first + 10 < last ? 10 : int(last - first), first);
26322640

2633-
for (const auto& p : mRegexList)
2641+
for (const auto& p : mRegexList->mValue)
26342642
{
26352643
bool regexSearchResult = false;
26362644
try { regexSearchResult = boost::regex_search(first, last, results, p.first, boost::regex_constants::match_continuous); }

TextEditor.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <unordered_set>
1111
#include <unordered_map>
1212
#include <map>
13-
#include <boost/regex.hpp>
1413
#include "imgui.h"
1514

1615
class IMGUI_API TextEditor
@@ -304,7 +303,6 @@ class IMGUI_API TextEditor
304303
UndoOperationType mType;
305304
};
306305

307-
typedef std::vector<std::pair<boost::regex, PaletteIndex>> RegexList;
308306

309307
class UndoRecord
310308
{
@@ -456,7 +454,6 @@ class IMGUI_API TextEditor
456454
Palette mPalette;
457455
LanguageDefinitionId mLanguageDefinitionId;
458456
const LanguageDefinition* mLanguageDefinition = nullptr;
459-
RegexList mRegexList;
460457

461458
inline bool IsHorizontalScrollbarVisible() const { return mCurrentSpaceWidth > mContentWidth; }
462459
inline bool IsVerticalScrollbarVisible() const { return mCurrentSpaceHeight > mContentHeight; }
@@ -469,4 +466,8 @@ class IMGUI_API TextEditor
469466
static const std::unordered_map<char, char> OPEN_TO_CLOSE_CHAR;
470467
static const std::unordered_map<char, char> CLOSE_TO_OPEN_CHAR;
471468
static PaletteId defaultPalette;
469+
470+
private:
471+
struct RegexList;
472+
std::shared_ptr<RegexList> mRegexList;
472473
};

0 commit comments

Comments
 (0)