Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
moontide
Dynamic-SSID-for-OpenWRT
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Dynamic-SSID-for-OpenWRT
/
functions.awk
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
51 lines (47 loc) · 1.84 KB
master
Breadcrumbs
Dynamic-SSID-for-OpenWRT
/
functions.awk
Copy path
Top
File metadata and controls
Code
Blame
51 lines (47 loc) · 1.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function init_char_int_index()
{
for (i=0; i<=255; i++)
{
t=sprintf ("%c", i);
_char_int_index[t]=i;
}
}
#
# 假设 UTF-8 字符串是被截断的,则删除被截断后的字符的剩余字节,以保证字符串的结尾不出现乱码
#
# 若要使用此函数,需要先在 BEGIN{} 中执行 init_char_int_index () 初始化函数来初始化 _char_int_index 数组
#
function fix_utf8_truncation(s)
{
len=split(s,a,"");
last_byte=_char_int_index[a[len]]; # 整个字符串的最后一个字节
if (debug) print " last_byte:", a[len], and(last_byte,0xc0) > "/dev/stderr";
if (and(last_byte,0xC0)==0x80 || and(last_byte,0xC0)==0xC0) #检查 utf-8 多字节字符被截断的情况
{
# 先找到 utf-8 字节序列的起始字节
for (i=len; i>=len-6; i--)
{
if(and(_char_int_index[a[i]],0xC0)==0xC0)
{
first_utf8_byte=_char_int_index[a[i]]; # 最后一个 utf-8 字符的首个字节
if (debug) print " 在", i, "处发现 utf-8 起始字节", first_utf8_byte > "/dev/stderr"
break;
}
}
bytes=0;
# 计算该 utf-8 字符应该有多少个字节组成(虽然通常汉字由 3 字节组成,但这样更灵活、通用,避免遇到 4 个字节的字符导致结果不符的情况)
while (and(first_utf8_byte,0x80)==0x80) # utf-8 首字节高位有多少位 1,就应该有多少个字节
{
first_utf8_byte=lshift(first_utf8_byte,1);
bytes++;
}
# 然后判断 utf-8 首字节到字符串结尾的长度是否等于 utf-8 字符的完整字节长度,如果不是,则删除被截断的 utf-8 字符字节
if ((len-i+1) != bytes)
{
if (debug) print " 本 utf-8 字符长度为", bytes, "字节,被截断后只剩下了", (len-i+1), "字节,这些字节应该被删除" > "/dev/stderr"
s=substr(s, 1, i-1);
if (debug) print "修复结束后的字符串: [" s "]" > "/dev/stderr";
}
}
return s;
}
You can’t perform that action at this time.