void parseS3Path()

in awsio/csrc/io/s3/s3_io.cpp [127:155]


void parseS3Path(const std::string &fname, std::string *bucket,
                 std::string *object) {
    if (fname.empty()) {
        throw std::invalid_argument{"The filename cannot be an empty string."};
    }

    if (fname.size() < 5 || fname.substr(0, 5) != "s3://") {
        throw std::invalid_argument{
            "The filename must start with the S3 scheme."};
    }

    std::string path = fname.substr(5);

    if (path.empty()) {
        throw std::invalid_argument{"The filename cannot be an empty string."};
    }

    auto pos = path.find_first_of('/');
    if (pos == 0) {
        throw std::invalid_argument{
            "The filename does not contain a bucket name."};
    }

    *bucket = path.substr(0, pos);
    *object = path.substr(pos + 1);
    if (pos == std::string::npos) {
        *object = "";
    }
}