1 /* Split a symbol name. 2 3 Copyright (C) 2022-2024 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 "split-name.h" 21 #include "cp-support.h" 22 23 /* See split-name.h. */ 24 25 std::vector<std::string_view> 26 split_name (const char *name, split_style style) 27 { 28 std::vector<std::string_view> result; 29 unsigned int previous_len = 0; 30 31 switch (style) 32 { 33 case split_style::CXX: 34 for (unsigned int current_len = cp_find_first_component (name); 35 name[current_len] != '\0'; 36 current_len += cp_find_first_component (name + current_len)) 37 { 38 gdb_assert (name[current_len] == ':'); 39 result.emplace_back (&name[previous_len], 40 current_len - previous_len); 41 /* Skip the '::'. */ 42 current_len += 2; 43 previous_len = current_len; 44 } 45 break; 46 47 case split_style::DOT_STYLE: 48 /* D and Go-style names. */ 49 for (const char *iter = strchr (name, '.'); 50 iter != nullptr; 51 iter = strchr (iter, '.')) 52 { 53 result.emplace_back (&name[previous_len], 54 iter - &name[previous_len]); 55 ++iter; 56 previous_len = iter - name; 57 } 58 break; 59 60 default: 61 break; 62 } 63 64 result.emplace_back (&name[previous_len]); 65 return result; 66 } 67 68