From 804e819c1bf64d4df483107e02e896b29e58b3f1 Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Wed, 23 Aug 2023 02:22:53 +0000 Subject: Move String8 path functions to androidfw and aapt Test: m checkbuild Bug: 295394788 Change-Id: I9488bc5632cbd47c83f6b5f2df4c87eb324a1e8e --- tools/aapt/Utils.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tools/aapt/Utils.cpp') diff --git a/tools/aapt/Utils.cpp b/tools/aapt/Utils.cpp index 36b018e7dd2c..946916a0598a 100644 --- a/tools/aapt/Utils.cpp +++ b/tools/aapt/Utils.cpp @@ -36,3 +36,26 @@ void convertToResPath([[maybe_unused]] String8& s) { } #endif } + +String8 walkPath(const String8& path, String8* outRemains) { + const char* cp; + const char* const str = path.c_str(); + const char* buf = str; + + cp = strchr(buf, OS_PATH_SEPARATOR); + if (cp == buf) { + // don't include a leading '/'. + buf = buf + 1; + cp = strchr(buf, OS_PATH_SEPARATOR); + } + + if (cp == nullptr) { + String8 res = buf != str ? String8(buf) : path; + if (outRemains) *outRemains = String8(); + return res; + } + + String8 res(buf, cp - buf); + if (outRemains) *outRemains = String8(cp + 1); + return res; +} -- cgit v1.2.3-59-g8ed1b