moved to "io" folder from "type"
This commit is contained in:
14
inc/hgl/io/LoadString.h
Normal file
14
inc/hgl/io/LoadString.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef HGL_LOAD_STRING_INCLUDE
|
||||
#define HGL_LOAD_STRING_INCLUDE
|
||||
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/CodePage.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
int LoadStringFromText(UTF8String &full_text,const void *source_data,const int size,const CharSet &cs=UTF8CharSet); ///<加载一个原始文本块到UTF8String
|
||||
int LoadStringFromText(UTF16String &full_text,const void *source_data,const int size,const CharSet &cs=UTF8CharSet); ///<加载一个原始文本块到UTF16String
|
||||
int LoadStringFromTextFile(UTF8String &str,const OSString &filename,const CharSet &cs=UTF8CharSet); ///<加载一个原始文本文件到UTF8String
|
||||
int LoadStringFromTextFile(UTF16String &str,const OSString &filename,const CharSet &cs=UTF8CharSet); ///<加载一个原始文本文件到UTF16String
|
||||
}//namespace hgl
|
||||
#endif//HGL_LOAD_STRING_INCLUDE
|
78
inc/hgl/io/LoadStringList.h
Normal file
78
inc/hgl/io/LoadStringList.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef HGL_LOAD_STRING_LIST_INCLUDE
|
||||
#define HGL_LOAD_STRING_LIST_INCLUDE
|
||||
|
||||
#include<hgl/type/StringList.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
template<typename T,ByteOrderMask bom> struct ReadStringFromDIS
|
||||
{
|
||||
bool ReadString(io::DataInputStream *dis,T &str);
|
||||
};
|
||||
|
||||
template<typename T> struct ReadStringFromDIS<T,ByteOrderMask::UTF8>
|
||||
{
|
||||
bool ReadString(io::DataInputStream *dis,T &str)
|
||||
{
|
||||
return dis->ReadUTF8String(str);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> struct ReadStringFromDIS<T,ByteOrderMask::UTF16LE>
|
||||
{
|
||||
bool ReadString(io::DataInputStream *dis,T &str)
|
||||
{
|
||||
return dis->ReadUTF16LEString(str);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> struct ReadStringFromDIS<T,ByteOrderMask::UTF16BE>
|
||||
{
|
||||
bool ReadString(io::DataInputStream *dis,T &str)
|
||||
{
|
||||
return dis->ReadUTF16BEString(str);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 从DataInputStream流中读取一个字符串列表
|
||||
* @param sl 字符串列表处理类
|
||||
* @param dis 数据输入流
|
||||
* @return 字符串行数
|
||||
*/
|
||||
template<typename T,ByteOrderMask bom> int LoadStringList(StringList<T> &sl,io::DataInputStream *dis)
|
||||
{
|
||||
if(!dis)return(-1);
|
||||
|
||||
int count;
|
||||
int result=0;
|
||||
|
||||
if(!dis->ReadInt32(count))
|
||||
return(-2);
|
||||
|
||||
ReadStringFromDIS<String<T>,bom> rsfd;
|
||||
|
||||
String<T> str;
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
if(!rsfd.ReadString(dis,str))
|
||||
break;
|
||||
|
||||
sl.Add(str);
|
||||
result++;
|
||||
}
|
||||
|
||||
return(result);
|
||||
}//int LoadStringList
|
||||
|
||||
inline int LoadUTF8StringList (UTF8StringList & sl,io::DataInputStream *dis){return LoadStringList<u8char, ByteOrderMask::UTF8 >(sl,dis);}
|
||||
inline int LoadUTF16LEStringList (UTF16StringList & sl,io::DataInputStream *dis){return LoadStringList<u16char, ByteOrderMask::UTF16LE >(sl,dis);}
|
||||
inline int LoadUTF16BEStringList (UTF16StringList & sl,io::DataInputStream *dis){return LoadStringList<u16char, ByteOrderMask::UTF16BE >(sl,dis);}
|
||||
|
||||
int LoadStringListFromText( UTF8StringList &sl,const void *data,const int size,const CharSet &cs=UTF8CharSet); ///<加载一个原始文本块到UTF8StringList
|
||||
int LoadStringListFromText( UTF16StringList &sl,const void *data,const int size,const CharSet &cs=UTF8CharSet); ///<加载一个原始文本块到UTF16StringList
|
||||
int LoadStringListFromTextFile( UTF8StringList &sl,const OSString &filename, const CharSet &cs=UTF8CharSet); ///<加载一个原始文本文件到UTF8StringList
|
||||
int LoadStringListFromTextFile( UTF16StringList &sl,const OSString &filename, const CharSet &cs=UTF8CharSet); ///<加载一个原始文本文件到UTF16StringList
|
||||
}//namespace hgl
|
||||
#endif//HGL_LOAD_STRING_LIST_INCLUDE
|
73
inc/hgl/io/SaveStringList.h
Normal file
73
inc/hgl/io/SaveStringList.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#ifndef HGL_SAVE_STRING_LIST_INCLUDE
|
||||
#define HGL_SAVE_STRING_LIST_INCLUDE
|
||||
|
||||
#include<hgl/type/StringList.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
template<typename T,ByteOrderMask bom> struct WriteStringToDOS
|
||||
{
|
||||
bool WriteString(io::DataOutputStream *dos,const T &str);
|
||||
};
|
||||
|
||||
template<typename T> struct WriteStringToDOS<T,ByteOrderMask::UTF8>
|
||||
{
|
||||
bool WriteString(io::DataOutputStream *dos,const T &str)
|
||||
{
|
||||
return dos->WriteUTF8String(str);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> struct WriteStringToDOS<T,ByteOrderMask::UTF16LE>
|
||||
{
|
||||
bool WriteString(io::DataOutputStream *dos,const T &str)
|
||||
{
|
||||
return dos->WriteUTF16LEString(str);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> struct WriteStringToDOS<T,ByteOrderMask::UTF16BE>
|
||||
{
|
||||
bool WriteString(io::DataOutputStream *dos,const T &str)
|
||||
{
|
||||
return dos->WriteUTF16BEString(str);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T,ByteOrderMask bom> int WriteStringList(io::DataOutputStream *dos,const StringList<T> &sl)
|
||||
{
|
||||
WriteStringToDOS<T,bom> wtd;
|
||||
|
||||
const int32 count=sl.GetCount();
|
||||
int result=0;
|
||||
|
||||
if(!dos->WriteInt32(count))
|
||||
return(-2);
|
||||
|
||||
for(int32 i=0;i<count;i++)
|
||||
{
|
||||
if(!wtd.WriteString(dos,sl[i]))
|
||||
return(-3);
|
||||
|
||||
result++;
|
||||
}
|
||||
|
||||
return(result);
|
||||
};
|
||||
|
||||
template<typename T> int SaveUTF8StringList(io::DataOutputStream *dos,const StringList<T> &sl)
|
||||
{
|
||||
return WriteStringList<T,ByteOrderMask::UTF8>(dos,sl);
|
||||
}
|
||||
|
||||
template<typename T> int SaveUTF16LEStringList(io::DataOutputStream *dos,const StringList<T> &sl)
|
||||
{
|
||||
return WriteStringList<T,ByteOrderMask::UTF16LE>(dos,sl);
|
||||
}
|
||||
|
||||
template<typename T> int SaveUTF16BEStringList(io::DataOutputStream *dos,const StringList<T> &sl)
|
||||
{
|
||||
return WriteStringList<T,ByteOrderMask::UTF16BE>(dos,sl);
|
||||
}
|
||||
}//namespace hgl
|
||||
#endif//HGL_SAVE_STRING_LIST_INCLUDE
|
Reference in New Issue
Block a user