Skip to content

Commit c5519ec

Browse files
authored
Merge pull request #2640 from allredj/support-for-load-containing-class-only
Class loading utils
2 parents 77185fd + 1f4ef40 commit c5519ec

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

jbmc/src/java_bytecode/java_class_loader_limit.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ void java_class_loader_limitt::setup_class_load_limit(
2424
// '@' signals file reading with list of class files to load
2525
use_regex_match = java_cp_include_files[0] != '@';
2626
if(use_regex_match)
27+
{
2728
regex_matcher=std::regex(java_cp_include_files);
29+
debug() << "Limit loading to classes matching '" << java_cp_include_files
30+
<< "'" << eom;
31+
}
2832
else
2933
{
3034
assert(java_cp_include_files.length()>1);
@@ -54,7 +58,10 @@ bool java_class_loader_limitt::load_class_file(const std::string &file_name)
5458
if(use_regex_match)
5559
{
5660
std::smatch string_matches;
57-
return std::regex_match(file_name, string_matches, regex_matcher);
61+
if(std::regex_match(file_name, string_matches, regex_matcher))
62+
return true;
63+
debug() << file_name + " discarded since not matching loader regexp" << eom;
64+
return false;
5865
}
5966
else
6067
// load .class file only if it is in the match set

src/util/string_utils.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,24 @@ std::string escape(const std::string &s)
148148

149149
return result;
150150
}
151+
152+
/// Replace all occurrences of a string inside a string
153+
/// \param [out] str: string to search
154+
/// \param from: string to replace
155+
/// \param to: string to replace with
156+
/// Copyright notice:
157+
/// Attributed to Gauthier Boaglio
158+
/// Source: https://stackoverflow.com/a/24315631/7501486
159+
/// Used under MIT license
160+
void replace_all(
161+
std::string &str,
162+
const std::string &from,
163+
const std::string &to)
164+
{
165+
size_t start_pos = 0;
166+
while((start_pos = str.find(from, start_pos)) != std::string::npos)
167+
{
168+
str.replace(start_pos, from.length(), to);
169+
start_pos += to.length();
170+
}
171+
}

src/util/string_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ Stream &join_strings(
6767
/// programming language.
6868
std::string escape(const std::string &);
6969

70+
void replace_all(std::string &, const std::string &, const std::string &);
71+
7072
#endif

0 commit comments

Comments
 (0)