LiteOS组件尝鲜-玩转Bidireference
01
基本信息
大部分语言单词或语句的书写顺序都是由左至右,也存在某些语言例如阿拉伯语的书写顺序是从右到左,对于这种非常规书写顺序的语言,计算机内如果没有专门标记方向的控制码,就会按照和英文一样的顺序来存储它的unicode码,渲染为字符显示在屏幕上时,我们看到的语言顺序便是反的。
此时需要对该语言的每个单词、每个段落,给出若干个标记方
向的控制码来指示它们的显示方向,如下表所示:
Abbr |
Code Point |
Name |
Description |
LRE |
U+202A |
LEFT-TO-RIGHT EMBEDDING |
Treat the following text as embedded left-to-right. |
RLE |
U+202B |
RIGHT-TO-LEFT EMBEDDING |
Treat the following text as embedded right-to-left. |
标记方向的控制码的文本缩写为LRE和RLE,它们的unicode编码 为U+202A和U+202B,分别表示让单词在渲染(显示)时从左到右排列,和从右到左排列。
Bidireference是一个通过C语言实现的轻量级解析双向字符的算法程序:输入一段已经标记如上控制码的文本,运行Unicode Bidirectional Algorithm算法,算法会将这段文本按照正确的排序(从左到右,或从右到左)渲染(显示)出来。
本文以Bidireference Demo为例,介绍Bidireference的使用说明。(注:license未注明,仅限于学习用途。)
02
解析-Bidireference Demo
本demo参考了bidireference源代码包中bidiref.c文件的测试接口,实现了对0X2000,0X2460双向字符进行"-u63", "-z", "-d3"算法解析,其中-u63为UBA算法类型,-z为静态测试,-d3为算法调试级别。
03
使能-Bidireference Demo
由于此组件需要较大的内存资源,暂时只有使用qemu运行的realview-pbx-a9和qemu-virt-a53工程支持,以realview-pbx-a9为例,执行以下操作:
~/Huawei_LiteOS$ cp tools/build/config/realview-pbx-a9.config .config
在LiteOS源码根目录下执行make menuconfig命令,按如下菜单路径使能Bidirefc Demo。
Demos --->
Utility Demo --->
[*] Enable Bidireference Demo (NEW)
使能Bidireference Demo后会自动使能Bidireference组件和ramfs文件系统。保存退出后,会从BidirefenceC官网上自动下载bidireference源代码,并从gitee上下载适配于LiteOS系统的patch包,并打入patch。详细流程在:
components/download.sh和components/utility/bidirefc/download_bidi.sh文件中。**注意:**如果下载bidireference源代码失败,需要到BidirefenceC官网手动下载。
04
测试结果
在Linux主机的LiteOS源码根目录下执行make clean ; make -j命令编译LiteOS工程,编译成功后将在~/Huawei_LiteOS/out/realview-pbx-a9/lib目录下生成组件库文件libbidirefc.a和此Demo库文件libbidireference_demo.a,系统镜像文件为Huawei_LiteOS.bin。
执行以下命令即可运行LiteOS工程,更详细的信息可以参考CORTEX A9在QEMU下运行LiteOS。
~/Huawei_LiteOS$ qemu-system-arm -machine realview-pbx-a9-smp4-m 512M -kernel out/realview-pbx-a9/Huawei_LiteOS.bin -nographic
Demo运行结果如下所示,可以看到此Demo根据UBA算法类型解析双向字符。
********Hello Huawei LiteOS********
LiteOS Kernel Version : 5.0.0
Processor : Cortex-A9 * 4
Run Mode : SMP
GIC Rev : GICv1
build time : Mar 13 2021 01:51:13
**********************************
main core booting up...
osAppInit
releasing 3 secondary cores
cpu 0 entering scheduler
cpu 3 entering scheduler
cpu 1 entering scheduler
cpu 2 entering scheduler
app init!
Hello, welcome to liteos demo!
Bidireference demo task start to run.
Current State: 1
Paragraph Dir: 2 (Dir_Auto), Paragraph Embed Level: 0, TextLen: 2
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Current State: 2
Paragraph Dir: 2 (Dir_Auto), Paragraph Embed Level: 0, TextLen: 2
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Current State: 3
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Current State: 4
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Current State: 5
Position: 0 1
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Current State: 6
Position: 0 1
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Seqs (L= 0):
Current State: 7
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Current State: 8
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Current State: 9
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Current State: 10
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Current State: 11
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Current State: 12
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Current State: 13
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Current State: 14
Text: 2000 2460
Bidi_Class: WS ON
Levels: 0 0
Runs:
Current State: 15
Text: 2000 2460
Bidi_Class: L L
Levels: 0 0
Runs:
Current State: 16
Text: 2000 2460
Bidi_Class: L L
Levels: 0 0
Runs:
Current State: 17
Text: 2000 2460
Bidi_Class: L L
Levels: 0 0
Runs:
Current State: 18
Text: 2000 2460
Bidi_Class: L L
Levels: 0 0
Runs:
Current State: 19
Text: 2000 2460
Bidi_Class: L L
Levels: 0 0
Runs:
Order: [0 1]
Bidireference demo task finished.
05
结语
未来我们还会持续新增更多组件、开发板、架构、特性等。
感谢您的阅读,有任何问题、建议,都可以留言给我们,让我们一起进步:
https://gitee.com/LiteOS/LiteOS/issues
为了更容易找到“LiteOS”代码仓,建议访问https://gitee.com/LiteOS/LiteOS,关注“ Watch”、点赞“Star”、并“Fork”到自己账号下,如下图。
- end -
- 点赞
- 收藏
- 关注作者
评论(0)