aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/FileSystemUtils.cpp
blob: c47f7509605a2101a955bc7d36482f759d8abdf5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/core/utils/FileSystemUtils.h>

using namespace Aws::Utils;

Aws::String PathUtils::GetFileNameFromPathWithoutExt(const Aws::String& path)
{
    Aws::String fileName = Aws::Utils::PathUtils::GetFileNameFromPathWithExt(path);
    size_t endPos = fileName.find_last_of('.');
    if (endPos == std::string::npos)
    {
        return fileName;
    } 
    if (endPos == 0) // fileName is "."
    {
        return {};
    }

    return fileName.substr(0, endPos);
}

Aws::String PathUtils::GetFileNameFromPathWithExt(const Aws::String& path)
{
    if (path.size() == 0) 
    {	
        return path;
    }

    size_t startPos = path.find_last_of(Aws::FileSystem::PATH_DELIM);
    if (startPos == path.size() - 1)
    {
        return {};
    }

    if (startPos == std::string::npos)
    {
        startPos = 0;
    }
    else 
    {
        startPos += 1;
    }

    size_t endPos = path.size() - 1;
    
    return path.substr(startPos, endPos - startPos + 1);
}