Example #1
0
String FilePath::dir_name(const char * path)
{
    String result = path;
    int sep = result.reverse_find(separator);
    if (sep >= 0) {
        if (sep == 0) {
            result.set_length(StringLength(separator));
        } else {
            result.set_length(sep);
        }
    } else {
        result.set_length(0);
    }

    return result;
}
Example #2
0
String FilePath::file_extension(const char * path)
{
    String result = path;
    int sep = result.reverse_find('.');
    if (sep >= 0) {
        result = path + sep;
    } else {
        result.set_length(0);
    }
    return result;
}
Example #3
0
/*!

\brief Read a block of data and store it in a String.
\ingroup System
\details Defined in dmzSystemFile.h.
Attempts to read \a Size number of bytes from \a File and store them in \a buffer.
\param[in] File C FILE * to read from.
\param[in] Size Size of data to attempt to read from \a File.
\param[out] buffer String to store read data in.
\return Returns dmz::True if any data was read.

*/
dmz::Int32
dmz::read_file (const FILE *File, const Int32 Size, String &buffer) {

    Int32 result (0);

    if (Size > 0) {

        buffer.set_buffer (0, Size + 1);

        if (buffer.get_size () >= Size) {

            result = fread ((void *)buffer.get_buffer (), sizeof (char), Size, (FILE *)File);
            buffer.set_length (result);
        }
    }

    return result;
}
Example #4
0
NAMEBEG

String FilePath::base_name(const char * path, bool with_extension /* = true */)
{
    String result = path;
    int sep = result.reverse_find(separator);
    if (sep >= 0) {
        result = path + sep + StringLength(separator);
    }

    if (!with_extension) {
        int dot = result.reverse_find('.');
        if (dot >= 0) {
            result.set_length(dot);
        }
    }
    return result;
}
Example #5
0
YETI_Result File::load(const char * path, String & data, FileInterface::open_mode mode /* = YETI_FILE_OPEN_MODE_READ */)
{
    DataBuffer buffer;

    data = "";

    File file(path);
    YETI_Result result = file.open(mode);
    if (YETI_FAILED(result)) return result;

    result = file.load(buffer);

    if (YETI_SUCCEEDED(result) && buffer.get_data_size() > 0) {
        data.assign((const char *)buffer.get_data(), buffer.get_data_size());
        data.set_length(buffer.get_data_size());
    }

    file.close();

    return result;
}