2023-01-17 13:01:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifndef ECMASCRIPT_BASE_PATH_HELPER_H
|
|
|
|
#define ECMASCRIPT_BASE_PATH_HELPER_H
|
|
|
|
|
2023-04-20 08:03:36 +00:00
|
|
|
#include "ecmascript/compiler/aot_file/aot_file_manager.h"
|
2023-03-16 08:48:37 +00:00
|
|
|
#include "ecmascript/base/string_helper.h"
|
2023-01-17 13:01:22 +00:00
|
|
|
#include "ecmascript/ecma_macros.h"
|
|
|
|
#include "ecmascript/ecma_string.h"
|
|
|
|
#include "ecmascript/ecma_vm.h"
|
|
|
|
#include "ecmascript/global_env.h"
|
|
|
|
#include "ecmascript/js_tagged_value-inl.h"
|
|
|
|
#include "ecmascript/jspandafile/js_pandafile.h"
|
|
|
|
|
|
|
|
namespace panda::ecmascript::base {
|
|
|
|
class PathHelper {
|
|
|
|
public:
|
2023-12-27 07:43:42 +00:00
|
|
|
static constexpr char COLON_TAG[] = ":";
|
2023-07-12 12:34:30 +00:00
|
|
|
static constexpr char CURRENT_DIREATORY_TAG[] = "./";
|
|
|
|
static constexpr char DOUBLE_POINT_TAG[] = "..";
|
|
|
|
static constexpr char DOUBLE_SLASH_TAG[] = "//";
|
|
|
|
static constexpr char NAME_SPACE_TAG = '@';
|
2024-04-06 06:44:00 +00:00
|
|
|
static constexpr char NORMALIZED_OHMURL_TAG = '&';
|
2023-07-12 12:34:30 +00:00
|
|
|
static constexpr char POINT_STRING_TAG[] = ".";
|
|
|
|
static constexpr char POINT_TAG = '.';
|
|
|
|
static constexpr char SLASH_TAG = '/';
|
|
|
|
|
|
|
|
static CString NormalizePath(const CString &fileName);
|
2024-07-14 12:08:14 +00:00
|
|
|
static CString ResolveDirPath(const CString &fileName);
|
2023-07-12 12:34:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Before: moduleName@nameSpace
|
|
|
|
* After: moduleName
|
|
|
|
*/
|
|
|
|
inline static void DeleteNamespace(CString &moduleName)
|
2023-03-08 03:35:52 +00:00
|
|
|
{
|
|
|
|
size_t pos = moduleName.find(NAME_SPACE_TAG);
|
|
|
|
if (pos == CString::npos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
moduleName.erase(pos, moduleName.size() - pos);
|
|
|
|
}
|
|
|
|
|
2024-04-06 06:44:00 +00:00
|
|
|
/*
|
|
|
|
* Before: moduleName@nameSpace
|
|
|
|
* After: nameSpace
|
|
|
|
*/
|
2024-05-04 10:28:21 +00:00
|
|
|
inline static CString GetHarName(const CString &moduleName)
|
2024-04-06 06:44:00 +00:00
|
|
|
{
|
|
|
|
size_t pos = moduleName.find(NAME_SPACE_TAG);
|
|
|
|
ASSERT(pos != CString::npos);
|
2024-05-04 10:28:21 +00:00
|
|
|
return moduleName.substr(pos + 1);
|
2024-04-06 06:44:00 +00:00
|
|
|
}
|
|
|
|
|
2023-07-12 12:34:30 +00:00
|
|
|
/*
|
|
|
|
* Before: bundleName/moduleName@namespace/moduleName/xxx/xxx
|
|
|
|
* After: moduleName/xxx/xxx
|
|
|
|
*/
|
|
|
|
inline static void AdaptOldIsaRecord(CString &recordName)
|
2023-02-01 03:27:49 +00:00
|
|
|
{
|
2023-07-12 12:34:30 +00:00
|
|
|
size_t pos = recordName.find(SLASH_TAG);
|
2023-02-01 03:27:49 +00:00
|
|
|
if (pos != CString::npos) {
|
2023-07-12 12:34:30 +00:00
|
|
|
pos = recordName.find(SLASH_TAG, pos + 1);
|
2023-02-01 03:27:49 +00:00
|
|
|
if (pos != CString::npos) {
|
|
|
|
recordName = recordName.substr(pos + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-12 12:34:30 +00:00
|
|
|
/*
|
2023-07-24 02:58:16 +00:00
|
|
|
* Before: @***:xxxx
|
|
|
|
* After: xxxx
|
2023-07-12 12:34:30 +00:00
|
|
|
*/
|
|
|
|
inline static CString GetStrippedModuleName(const CString &moduleRequestName)
|
2023-06-01 11:30:08 +00:00
|
|
|
{
|
2023-07-12 12:34:30 +00:00
|
|
|
size_t pos = moduleRequestName.find(COLON_TAG);
|
2023-06-01 11:30:08 +00:00
|
|
|
if (pos == CString::npos) {
|
|
|
|
LOG_FULL(FATAL) << "Unknown format " << moduleRequestName;
|
|
|
|
}
|
|
|
|
return moduleRequestName.substr(pos + 1);
|
|
|
|
}
|
|
|
|
|
2023-07-12 12:34:30 +00:00
|
|
|
/*
|
|
|
|
* Before: @xxx:****
|
|
|
|
* After: xxx
|
|
|
|
*/
|
|
|
|
inline static CString GetInternalModulePrefix(const CString &moduleRequestName)
|
2023-06-01 11:30:08 +00:00
|
|
|
{
|
2023-07-12 12:34:30 +00:00
|
|
|
size_t pos = moduleRequestName.find(COLON_TAG);
|
2023-06-01 11:30:08 +00:00
|
|
|
if (pos == CString::npos) {
|
|
|
|
LOG_FULL(FATAL) << "Unknown format " << moduleRequestName;
|
|
|
|
}
|
2024-05-04 10:22:49 +00:00
|
|
|
ASSERT(pos != 0);
|
2023-06-01 11:30:08 +00:00
|
|
|
return moduleRequestName.substr(1, pos - 1);
|
|
|
|
}
|
2023-01-17 13:01:22 +00:00
|
|
|
};
|
|
|
|
} // namespace panda::ecmascript::base
|
|
|
|
#endif // ECMASCRIPT_BASE_PATH_HELPER_H
|