MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / path_to

Method path_to

modules/gui/gui/src/backend/text_server/ustring.cpp:5210–5295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5208}
5209
5210String String::path_to(const String& p_path) const
5211{
5212 String src = this->replace("\\", "/");
5213 String dst = p_path.replace("\\", "/");
5214 if (!src.ends_with("/"))
5215 {
5216 src += "/";
5217 }
5218 if (!dst.ends_with("/"))
5219 {
5220 dst += "/";
5221 }
5222
5223 if (src.begins_with("res://") && dst.begins_with("res://"))
5224 {
5225 src = src.replace("res://", "/");
5226 dst = dst.replace("res://", "/");
5227 }
5228 else if (src.begins_with("user://") && dst.begins_with("user://"))
5229 {
5230 src = src.replace("user://", "/");
5231 dst = dst.replace("user://", "/");
5232 }
5233 else if (src.begins_with("/") && dst.begins_with("/"))
5234 {
5235 // nothing
5236 }
5237 else
5238 {
5239 // dos style
5240 String src_begin = src.get_slicec('/', 0);
5241 String dst_begin = dst.get_slicec('/', 0);
5242
5243 if (src_begin != dst_begin)
5244 {
5245 return p_path; // impossible to do this
5246 }
5247
5248 src = src.substr(src_begin.length(), src.length());
5249 dst = dst.substr(dst_begin.length(), dst.length());
5250 }
5251
5252 // remove leading and trailing slash and split
5253 Vector<String> src_dirs = src.substr(1, src.length() - 2).split("/");
5254 Vector<String> dst_dirs = dst.substr(1, dst.length() - 2).split("/");
5255
5256 // find common parent
5257 int common_parent = 0;
5258
5259 while (true)
5260 {
5261 if (src_dirs.size() == common_parent)
5262 {
5263 break;
5264 }
5265 if (dst_dirs.size() == common_parent)
5266 {
5267 break;

Callers 1

path_to_fileMethod · 0.80

Calls 8

replaceMethod · 0.95
begins_withMethod · 0.80
get_slicecMethod · 0.80
ends_withMethod · 0.45
substrMethod · 0.45
lengthMethod · 0.45
splitMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected