px普贤教程PuXian
普贤教程 › 包参考

strcase 包

命名风格转换

项值
包名strcase
版本0.2.0
可用版本0.1.0 / 0.2.0
入口strcase.px
分类文本与中文处理
文件数 / 行数1 / 275

安装与引入

bash
pxpkg init          # 首次
pxpkg add strcase@0.2.0
pxpkg install
px
import strcase
所属分类教程:文本与中文处理

公开接口

函数参数
str_wordss
str_snakes
str_kebabs
str_screaming_snakes
str_camels
str_pascals
str_title_wordss
其余 24 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
sc_is_upperc
sc_is_lowerc
sc_is_digitc
sc_is_spacec
sc_is_sepc
sc_joinwords, sep, mode
sc_camel_joinwords, pascal
str_trains
str_dots
str_paths
str_lower_wordss
str_upper_wordss
str_capitalizes
str_uncapitalizes
str_swap_cases
str_reverses
str_repeats, n
str_pad_lefts, width, ch = " "
str_pad_rights, width, ch = " "
str_pad_centers, width, ch = " "
str_counts, sub
str_is_uppers
str_is_lowers
str_is_titles

包内说明(源码头注释)

text
============================================================
普贤生态库:registry/strcase —— 命名风格转换
------------------------------------------------------------
纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。
对齐 Rust heck / convert_case、Go iancoleman/strcase、Python inflection 心智:
str_snake(s)           → "FooBar"  → "foo_bar"
str_kebab(s)           → "FooBar"  → "foo-bar"
str_camel(s)           → "foo_bar" → "fooBar"
str_pascal(s)          → "foo_bar" → "FooBar"
str_screaming_snake(s) → "FooBar"  → "FOO_BAR"
str_title_words(s)     → "foo_bar" → "Foo Bar"
str_words(s)           → 分词结果 list(供自定义风格)
分词规则(heck 风格):
- 分隔符(空格 / - / _ / . / / / \\\\ / 制表换行回车)断开
- lower/digit → upper 处断开(camelCase → camel + Case)
- 连续大写后接小写时,在最后一个大写前断开(HTTPServer → HTTP + Server)
- 数字并入相邻单词(sha256 → sha256)
说明:面向 ASCII 标识符;非 ASCII 字符按原字符并入当前词(不按字节切割)。
大小写判定用 to_upper/to_lower(m197 已有原生 ord;PX-DEF-013 为对方跳号不存在,勿引用)。
============================================================
---- 字符分类 ----