1 | /* |
---|---|
2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
5 | * You may not use this file except in compliance with the License. |
6 | * A copy of the License is located at |
7 | * |
8 | * http://aws.amazon.com/apache2.0 |
9 | * |
10 | * or in the "license" file accompanying this file. This file is distributed |
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
12 | * express or implied. See the License for the specific language governing |
13 | * permissions and limitations under the License. |
14 | */ |
15 | |
16 | #include <aws/core/utils/FileSystemUtils.h> |
17 | |
18 | using namespace Aws::Utils; |
19 | |
20 | Aws::String PathUtils::GetFileNameFromPathWithoutExt(const Aws::String& path) |
21 | { |
22 | Aws::String fileName = Aws::Utils::PathUtils::GetFileNameFromPathWithExt(path); |
23 | size_t endPos = fileName.find_last_of('.'); |
24 | if (endPos == std::string::npos) |
25 | { |
26 | return fileName; |
27 | } |
28 | if (endPos == 0) // fileName is "." |
29 | { |
30 | return {}; |
31 | } |
32 | |
33 | return fileName.substr(0, endPos); |
34 | } |
35 | |
36 | Aws::String PathUtils::GetFileNameFromPathWithExt(const Aws::String& path) |
37 | { |
38 | if (path.size() == 0) |
39 | { |
40 | return path; |
41 | } |
42 | |
43 | size_t startPos = path.find_last_of(Aws::FileSystem::PATH_DELIM); |
44 | if (startPos == path.size() - 1) |
45 | { |
46 | return {}; |
47 | } |
48 | |
49 | if (startPos == std::string::npos) |
50 | { |
51 | startPos = 0; |
52 | } |
53 | else |
54 | { |
55 | startPos += 1; |
56 | } |
57 | |
58 | size_t endPos = path.size() - 1; |
59 | |
60 | return path.substr(startPos, endPos - startPos + 1); |
61 | } |
62 |