String::CPtr resolve(JsArray::CPtr paths) { const Size kMax = 8192; char dir[kMax]; char* r = getcwd(dir, kMax); if (!r) return String::null(); if (!paths) return String::create(dir); StringBuilder::Ptr resolved = StringBuilder::create(); resolved->appendStr(dir); Size len = paths->length(); for (Size i = 0; i < len; i++) { String::CPtr path = paths->getCPtr<String>(i); if (path) { if (isSep(path->charAt(0))) { resolved = StringBuilder::create(); #ifdef LIBJ_PF_WINDOWS // append the drive letter resolved->appendChar(dir[0]); resolved->appendChar(dir[1]); } else if (isAlpha(path->charAt(0)) && path->charAt(1) == ':') { resolved = StringBuilder::create(); #endif } else if (!path->isEmpty()) { resolved->appendChar(SEP); } resolved->appendStr(path); } } return trimSeps(normalize(resolved->toString())); }
String::CPtr percentDecode(String::CPtr str, String::Encoding enc) { if (!str || str->isEmpty()) return String::create(); Size len = str->length() + 1; char* decoded = new char[len]; Size size = percentDecode(decoded, len, str->toStdString().c_str()); String::CPtr res; switch (enc) { case String::UTF8: res = String::create(decoded, enc, size); break; case String::UTF16: case String::UTF16BE: case String::UTF16LE: res = String::create(decoded, enc, size >> 1); break; case String::UTF32: case String::UTF32BE: case String::UTF32LE: res = String::create(decoded, enc, size >> 2); break; default: assert(false); res = String::null(); } delete[] decoded; return res; }