1 /* Split a symbol name. 2 3 Copyright (C) 2022-2023 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20 #include "defs.h" 21 #include "split-name.h" 22 #include "cp-support.h" 23 24 /* See split-name.h. */ 25 26 std::vector<gdb::string_view> 27 split_name (const char *name, split_style style) 28 { 29 std::vector<gdb::string_view> result; 30 unsigned int previous_len = 0; 31 32 switch (style) 33 { 34 case split_style::CXX: 35 for (unsigned int current_len = cp_find_first_component (name); 36 name[current_len] != '\0'; 37 current_len += cp_find_first_component (name + current_len)) 38 { 39 gdb_assert (name[current_len] == ':'); 40 result.emplace_back (&name[previous_len], 41 current_len - previous_len); 42 /* Skip the '::'. */ 43 current_len += 2; 44 previous_len = current_len; 45 } 46 break; 47 48 case split_style::UNDERSCORE: 49 /* Handle the Ada encoded (aka mangled) form here. */ 50 for (const char *iter = strstr (name, "__"); 51 iter != nullptr; 52 iter = strstr (iter, "__")) 53 { 54 result.emplace_back (&name[previous_len], 55 iter - &name[previous_len]); 56 iter += 2; 57 previous_len = iter - name; 58 } 59 break; 60 61 case split_style::DOT: 62 /* D and Go-style names. */ 63 for (const char *iter = strchr (name, '.'); 64 iter != nullptr; 65 iter = strchr (iter, '.')) 66 { 67 result.emplace_back (&name[previous_len], 68 iter - &name[previous_len]); 69 ++iter; 70 previous_len = iter - name; 71 } 72 break; 73 74 default: 75 break; 76 } 77 78 result.emplace_back (&name[previous_len]); 79 return result; 80 } 81 82