From 60d985370e63cb3b4c68489fc54276d8ac2b921b Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 11 Mar 2010 19:19:33 -0800 Subject: Add startswith/endswith helpers Inspired by the Python equivalents, these new utility functions just make it a little cleaner to match at the beginning or end of a string. --- tapsets.cxx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index 2068d5f4..b572f4e0 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -2766,7 +2766,7 @@ void dwarf_cast_expanding_visitor::filter_special_modules(string& module) // look for "" or "kernel" // for those cases, build a module including that header if (module[module.size() - 1] == '>' && - (module[0] == '<' || module.compare(0, 7, "kernel<") == 0)) + (module[0] == '<' || startswith(module, "kernel<"))) { string cached_module; if (s.use_cache) @@ -3768,7 +3768,7 @@ sdt_var_expanding_visitor::visit_target_symbol (target_symbol *e) return; } - if (e->base_name.find("$arg") == string::npos || ! have_reg_args) + if (!startswith(e->base_name, "$arg") || ! have_reg_args) { // NB: uprobes-based sdt.h; $argFOO gets resolved later. // XXX: We don't even know the arg_count in this case. @@ -6463,7 +6463,7 @@ tracepoint_query::handle_query_func(Dwarf_Die * func) { dw.focus_on_function (func); - assert(dw.function_name.compare(0, 10, "stapprobe_") == 0); + assert(startswith(dw.function_name, "stapprobe_")); string tracepoint_instance = dw.function_name.substr(10); // check for duplicates -- sometimes tracepoint headers may be indirectly @@ -6609,13 +6609,10 @@ tracepoint_builder::init_dw(systemtap_session& s) string header(trace_glob.gl_pathv[i]); // filter out a few known "internal-only" headers - if (header.find("/define_trace.h") != string::npos) - continue; - if (header.find("/ftrace.h") != string::npos) - continue; - if (header.find("/trace_events.h") != string::npos) - continue; - if (header.find("_event_types.h") != string::npos) + if (endswith(header, "/define_trace.h") || + endswith(header, "/ftrace.h") || + endswith(header, "/trace_events.h") || + endswith(header, "_event_types.h")) continue; system_headers.push_back(header); -- cgit