55
66namespace fasm {
77
8- void parse_name_with_optional_index (const std::string in, std::string *name, int *index) {
8+ void parse_name_with_optional_index (std::string_view in, std::string *name, int *index) {
99 auto in_parts = vtr::split (in, " []" );
1010
1111 if (in_parts.size () == 1 ) {
@@ -16,13 +16,13 @@ void parse_name_with_optional_index(const std::string in, std::string *name, int
1616 *index = vtr::atoi (in_parts[1 ]);
1717 } else {
1818 vpr_throw (VPR_ERROR_OTHER, __FILE__, __LINE__,
19- " Cannot parse %s." , in.c_str ());
19+ " Cannot parse %s." , in.data ());
2020 }
2121}
2222
2323std::vector<std::string> split_fasm_entry (std::string entry,
24- std::string delims,
25- std::string ignore) {
24+ std::string_view delims,
25+ std::string_view ignore) {
2626 for (size_t ii=0 ; ii<entry.length (); ii++) {
2727 while (ignore.find (entry[ii]) != std::string::npos) {
2828 entry.erase (ii, 1 );
@@ -32,7 +32,7 @@ std::vector<std::string> split_fasm_entry(std::string entry,
3232 return vtr::split (entry, delims);
3333}
3434
35- std::vector<std::string> find_tags_in_feature (const std::string& a_String) {
35+ std::vector<std::string> find_tags_in_feature (std::string_view a_String) {
3636 const std::regex regex (" (\\ {[a-zA-Z0-9_]+\\ })" );
3737
3838 std::vector<std::string> tags;
@@ -51,17 +51,17 @@ std::vector<std::string> find_tags_in_feature (const std::string& a_String) {
5151 return tags;
5252}
5353
54- std::string substitute_tags (const std::string& a_Feature, const std::map<const std::string, std::string>& a_Tags) {
54+ std::string substitute_tags (std::string_view a_Feature, const std::map<const std::string, std::string>& a_Tags) {
5555
5656 // First list tags that are given in the feature string
5757 auto tags = find_tags_in_feature (a_Feature);
5858 if (tags.empty ()) {
59- return a_Feature;
59+ return std::string{ a_Feature} ;
6060 }
6161
6262 // Check if those tags are defined, If not then throw an error
6363 bool have_errors = false ;
64- for (auto tag: tags) {
64+ for (const auto & tag: tags) {
6565 if (a_Tags.count (tag) == 0 ) {
6666 vtr::printf_error (__FILE__, __LINE__, " fasm placeholder '%s' not defined!" , tag.c_str ());
6767 have_errors = true ;
@@ -71,13 +71,13 @@ std::string substitute_tags (const std::string& a_Feature, const std::map<const
7171 if (have_errors) {
7272 vpr_throw (VPR_ERROR_OTHER, __FILE__, __LINE__,
7373 " fasm feature '%s' contains placeholders that are not defined for the tile that it is used in!" ,
74- a_Feature.c_str ()
74+ a_Feature.data ()
7575 );
7676 }
7777
7878 // Substitute tags
7979 std::string feature (a_Feature);
80- for (auto tag: tags) {
80+ for (const auto & tag: tags) {
8181 std::regex regex (" \\ {" + tag + " \\ }" );
8282 feature = std::regex_replace (feature, regex, a_Tags.at (tag));
8383 }
0 commit comments