Пример #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;
}
Пример #2
0
NAMEBEG

YETI_Result Environment::get(const char * name, String& value)
{
    char * env;

    value.set_length(0);

#if defined(YETI_CONFIG_HAVE_GETENV)
    env = getenv(name);
    if (env) {
        value = env;
        return YETI_SUCCESS;
    } else {
        return YETI_ERROR_NO_SUCH_ITEM;
    }
#elif defined(YETI_CONFIG_HAVE_DUPENV_S)
    if (dupenv_s(&env, NULL, name) != 0) {
        return YETI_FAILURE;
    } else if (env != NULL) {
        value = env;
        free(env);
        return YETI_SUCCESS;
    } else {
        return YETI_ERROR_NO_SUCH_ITEM;
    }
#else
    return YETI_ERROR_NOT_SUPPORTED;
#endif
}
Пример #3
0
/*!

\brief Trims ASCII white space from front and back of the String.
\details Defined in dmzTypesStringUtil.h.
This function remove white space from the front and back of the string passed in.
For example the string " this is a string " would be converted to "this is a string".
\param[in,out] value String to have white space trimmed.

*/
void
dmz::trim_ascii_white_space (String &value) {

   Boolean done (False);
   Int32 length (value.get_length ());
   Int32 count (length - 1);

   while (!done) {

      if (count < 0) { done = True; }
      else if (!is_ascii_white_space (value.get_char (count))) { done = True; }
      else { count--; }
   }

   if (count < (length - 1)) { value.set_length (count + 1); }

   done = False;
   length = value.get_length ();
   count = 0;

   while (!done) {

      if (count >= length) { done = True; }
      else if (!is_ascii_white_space (value.get_char (count))) { done = True; }
      else { count++; }
   }

   if (count) { value.shift (-count); }
}
Пример #4
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;
}
Пример #5
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;
}
Пример #6
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;
}
Пример #7
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;
}