openoffice osl模块学习1
由“ can i get a char* , please?"看起:
Just barely. OO.o has at least six string wrappers, although the C implementations are of little interest:
rtl_String
— sal/inc/rtl/string.h
"Normal" string plus reference counting.rtlstring-
>buffer
is useful, as isrtlstring-
>length
. This object encapsulates an generic 8bit string - of unknown encoding. Feel free to treatrtlstring-
>buffer
as your belovedchar *
. If you really want to look at the implementation of somertl_String
function and lxr nor grep can help you, have a look at sal/rtl/source/strtmpl.c.OString
— sal/inc/rtl/string.hxx
Simply a rtl_String wrapped inside aclass
; you can useostring.pData
to get at the rtl_String (it's public).OString
has reasonably useful methods for if you need them.rtl_uString
— sal/inc/rtl/ustring.h
"Normal" Unicode string, similar to rtl_String, and refcounted as well. However, this one always comes in UCS-2 encoding, presumably to be compatible with Java's questionable choices. Seertl_String
above to find where the implementation of somertl_uString
functions is hidden.OUString
— sal/inc/rtl/ustring.hxx
An rtl_uString wrapped inside aclass
. This is what most of the OO.o code uses to pass strings around. To convert anOString
to anOUString
it is necessary to specify the character set of theOString
see;sal/inc/rtl/textenc.h
— the only interesting case isRTL_TEXTENCODING_UTF8
String
— tools/inc/string.hxx
This is an obsolete string class, aliased to 'UniString'. It has a number of limitations such as a 64k length limit. You can have the buffer withGetBuffer()
, but it's Utf-16 encoded.
A couple of conversion functions are really useful here, particularly:
rtl::OString aOString = ::rtl::OUStringToOString (aOUString, RTL_TEXTENCODING_UTF8);
And the reverse:
rtl::OUString aOUString = ::rtl::OStringToOUString (aOString, RTL_TEXTENCODING_UTF8);
If you just want to programattically print out a string for debugging purposes you probably want define a macro like :
#define CHAR_POINTER(THE_OUSTRING) ::rtl::OUStringToOString (THE_OUSTRING, RTL_TEXTENCODING_UTF8).pData->buffer
and use it like :
printf ( "SvXMLNamespaceMap::AddIfKnown : %s / %s\n", CHAR_POINTER(rPrefix), CHAR_POINTER(rName) );
.
For the obsolete String class, aliased UniString, it's like :
printf ( "rGrfName : %s\n", ByteString( rGrfName, RTL_TEXTENCODING_UTF8).GetBuffer() );
To print the value of rtl::OUString directly in the debugger, you can use dbg_dump()
. It is intended to be called interactively from the debugger, in both debug and non-debug builds of OOo. You can see the definition in sal/rtl/source/debugprint.cxx.
Some code snippets about manipulating those objects can be found on the codesnippets service page : [1]
原文链接:https://wiki.openoffice.org/wiki/Hacking#Can_I_get_a_char_.2A.2C_please.3F
继续看sal模块源码,摘录:
/********************************************************************************/
/* Data types
*/
/* Boolean */
typedef unsigned char sal_Bool;
# define sal_False ((sal_Bool)0)
# define sal_True ((sal_Bool)1)
/* char is assumed to always be 1 byte long */
typedef signed char sal_Int8;
typedef unsigned char sal_uInt8;
#if SAL_TYPES_SIZEOFSHORT == 2
typedef signed short sal_Int16;
typedef unsigned short sal_uInt16;//2字节
#else
#error "Could not find 16-bit type, add support for your architecture"
#endif
typedef char sal_Char;//1字节
#if ( defined(SAL_W32) && !defined(__MINGW32__) )
typedef wchar_t sal_Unicode;
#else
#define SAL_UNICODE_NOTEQUAL_WCHAR_T
typedef sal_uInt16 sal_Unicode;//2字节
#endif
“Normal” string, 8-bit string, unknown encoding 字符串操作c函数
/** The implementation of a byte string.
@internal
*/
typedef struct _rtl_String
{
oslInterlockedCount refCount; /* opaque */
sal_Int32 length;
sal_Char buffer[1];
} rtl_String;//1字节,8bit string
rtlstring wrapped inside a class openoffice的字符串类OString
class OString
{
public:
/** @internal */
rtl_String * pData;
usc-2 encoding 一组对unicode字符串操作的c函数
/** The implementation of a Unicode string.
@internal
*/
typedef struct _rtl_uString
{
oslInterlockedCount refCount; /* opaque */
sal_Int32 length;
sal_Unicode buffer[1];
} rtl_uString;
void SAL_CALL rtl_string2UString( rtl_uString ** newStr, const sal_Char * str, sal_Int32 len, rtl_TextEncoding encoding, sal_uInt32 convertFlags ) SAL_THROW_EXTERN_C();
rtl_ustring wrapped in a class openoffice的OUString类,封装rtl_ustring的c++类
#include <rtl/ustring.h> //rtl_uString
#include <rtl/string.hxx>// OString
class OUString
{
public:
/** @internal */
rtl_uString * pData;
OUString( const sal_Char * value, sal_Int32 length,
rtl_TextEncoding encoding,
sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
{
pData = 0;
rtl_string2UString( &pData, value, length, encoding, convertFlags );
#if defined EXCEPTIONS_OFF
OSL_ASSERT(pData != NULL);
#else
if (pData == 0) {
throw std::bad_alloc();
}
#endif
}
inline OUString OStringToOUString( const OString & rStr,
rtl_TextEncoding encoding,
sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
{
return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
}
inline OString OUStringToOString( const OUString & rUnicode,
rtl_TextEncoding encoding,
sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
{
return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
}
转载于:https://www.cnblogs.com/zhyryxz/p/3782298.html
openoffice osl模块学习1相关推荐
- python 的日志logging模块学习
2019独角兽企业重金招聘Python工程师标准>>> python 的日志logging模块学习 分类: python 2011-08-02 23:51 8338人阅读 评论(0) ...
- python中configparser_python中confIgparser模块学习
python中configparser模块学习 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section ...
- python textwrap_python2.7.3编译python模块学习- textwrap 文本包装和填充
python模块学习- textwrap 文本包装和填充 代码实例: sample_text = ''' The textwrap module can beused to format text f ...
- android fm模块学习,AndroidFM模块学习之5关闭FM流程
AndroidFM模块学习之五关闭FM流程 前一阵子简单描述了一些关于FM开启.录音和搜索的流程,浅析了一下各个类的源码,接下来就是关闭FM了,FM模块的学习就告一段落了,希望这阵子的整理能对大家在F ...
- python中的glob 模块学习文件路径查找
glob glob.glob(pathname), 返回所有匹配的文件路径列表.它只有一个参数pathname,定义了文件路径匹配规则,这里可以是绝对路径,也可以是相对路径. import glob ...
- pythontemp_python 临时文件夹 的 tempfile模块学习
python的临时文件夹的tempfile模块学习 应用程序经常要保存一些临时的信息,这些信息不是特别重要,没有必要写在配置文件 里,但又不能没有,这时候就可以把这些信息写到临时文件里.其实很 多程序 ...
- python logging模块学习
python 的日志logging模块学习 1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.in ...
- Python模块学习 - 用tinify模块压缩和优化图片
Python模块学习 - 用tinify模块压缩和优化图片 tinify模块 功能描述:TinyPNG和TinyJPG网站提供了压缩和优化.png和.jpg格式图片的功能.虽然可以很轻松地使用网页版进 ...
- VTK模块学习(一)
VTK模块学习(一) 文章目录 VTK模块学习(一) 1.仅依赖于cmake编译好的VTK 2.基于OpenCV编译下的VTK 1.仅依赖于cmake编译好的VTK 推荐一篇博客:<VTK基础及 ...
最新文章
- 弹性板计算和板带划分计算_计算双面太阳能板背面太阳辐射的新方法
- phpstorm自动补全
- 乔治城计算机系如何,乔治城大学cs专业申请
- 通过Wi-Fi将iPhone与Mac同步的教程
- java添加文本框和标签_如何在column.expression中插入文本框或标签的值?
- Guns二次开发目录
- 样式小图标的三种处理方式
- 尚学堂Spring视频教程(七):AOP XML
- 使用pytorch进行深度学习网络模型训练,实现车型识别
- 淘宝商品详情接口(商品详情页面数据接口)
- 高速高精度直线电机模组运输存放及安装维护的注意事项
- 数字城市:智慧水库(泉舟时代)
- AndroidWear官方文档总结05 - 手持设备与穿戴设备的通知同步
- 2020.07 学习日记
- 读《Linking Convolutional Neural Networks with Graph Convolutional Networks: Application in Pulmonary》
- Zookeeper到底是AP还是CP?
- 通过NTP协议进行网络授时时钟同步服务
- 高通Camera 驱动调试要点(一)
- Hugging face预训练模型下载和使用
- Java微信开发入门