由“ 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 is rtlstring->length. This object encapsulates an generic 8bit string - of unknown encoding. Feel free to treat rtlstring->buffer as your beloved char *. If you really want to look at the implementation of some rtl_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 a class; you can use ostring.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. See rtl_String above to find where the implementation of some rtl_uStringfunctions is hidden.

  • OUString — sal/inc/rtl/ustring.hxx
    An rtl_uString wrapped inside a class. This is what most of the OO.o code uses to pass strings around. To convert an OString to an OUString it is necessary to specify the character set of the OString see; sal/inc/rtl/textenc.h — the only interesting case is RTL_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 with GetBuffer(), 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相关推荐

  1. python 的日志logging模块学习

    2019独角兽企业重金招聘Python工程师标准>>> python 的日志logging模块学习 分类: python 2011-08-02 23:51 8338人阅读 评论(0) ...

  2. python中configparser_python中confIgparser模块学习

    python中configparser模块学习 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section ...

  3. python textwrap_python2.7.3编译python模块学习- textwrap 文本包装和填充

    python模块学习- textwrap 文本包装和填充 代码实例: sample_text = ''' The textwrap module can beused to format text f ...

  4. android fm模块学习,AndroidFM模块学习之5关闭FM流程

    AndroidFM模块学习之五关闭FM流程 前一阵子简单描述了一些关于FM开启.录音和搜索的流程,浅析了一下各个类的源码,接下来就是关闭FM了,FM模块的学习就告一段落了,希望这阵子的整理能对大家在F ...

  5. python中的glob 模块学习文件路径查找

    glob glob.glob(pathname), 返回所有匹配的文件路径列表.它只有一个参数pathname,定义了文件路径匹配规则,这里可以是绝对路径,也可以是相对路径. import glob ...

  6. pythontemp_python 临时文件夹 的 tempfile模块学习

    python的临时文件夹的tempfile模块学习 应用程序经常要保存一些临时的信息,这些信息不是特别重要,没有必要写在配置文件 里,但又不能没有,这时候就可以把这些信息写到临时文件里.其实很 多程序 ...

  7. python logging模块学习

    python 的日志logging模块学习 1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.in ...

  8. Python模块学习 - 用tinify模块压缩和优化图片

    Python模块学习 - 用tinify模块压缩和优化图片 tinify模块 功能描述:TinyPNG和TinyJPG网站提供了压缩和优化.png和.jpg格式图片的功能.虽然可以很轻松地使用网页版进 ...

  9. VTK模块学习(一)

    VTK模块学习(一) 文章目录 VTK模块学习(一) 1.仅依赖于cmake编译好的VTK 2.基于OpenCV编译下的VTK 1.仅依赖于cmake编译好的VTK 推荐一篇博客:<VTK基础及 ...

最新文章

  1. 弹性板计算和板带划分计算_计算双面太阳能板背面太阳辐射的新方法
  2. phpstorm自动补全
  3. 乔治城计算机系如何,乔治城大学cs专业申请
  4. 通过Wi-Fi将iPhone与Mac同步的教程
  5. java添加文本框和标签_如何在column.expression中插入文本框或标签的值?
  6. Guns二次开发目录
  7. 样式小图标的三种处理方式
  8. 尚学堂Spring视频教程(七):AOP XML
  9. 使用pytorch进行深度学习网络模型训练,实现车型识别
  10. 淘宝商品详情接口(商品详情页面数据接口)
  11. 高速高精度直线电机模组运输存放及安装维护的注意事项
  12. 数字城市:智慧水库(泉舟时代)
  13. AndroidWear官方文档总结05 - 手持设备与穿戴设备的通知同步
  14. 2020.07 学习日记
  15. 读《Linking Convolutional Neural Networks with Graph Convolutional Networks: Application in Pulmonary》
  16. Zookeeper到底是AP还是CP?
  17. 通过NTP协议进行网络授时时钟同步服务
  18. 高通Camera 驱动调试要点(一)
  19. Hugging face预训练模型下载和使用
  20. Java微信开发入门

热门文章

  1. html网页导入帝国系统,火车头采集文章并导入帝国CMS的教程
  2. net slim 分割_TensorFlow-Slim图像分类模型库
  3. 自己写搜索引擎?这里有一份大牛写的详细教程
  4. 爬虫课程笔记(二)Requests、代理、cookie和session
  5. LaTeX常用的数学符号
  6. 简图记录-《血酬定律》阅读总结
  7. 简单理解冯诺依曼计算机模型
  8. 【网易C计划重磅启动】参与开源分布式存储Curve,抢校招offer!
  9. SIGBUS SIGSEGV
  10. 机器学习-近9年双色球开奖数据的频繁项集