Skip to content

Commit

Permalink
depend jstrs: encodeUTF8 & decodeUTF8
Browse files Browse the repository at this point in the history
  • Loading branch information
zswang committed Mar 1, 2016
1 parent b4ccff6 commit 8f1522f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 32 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jpacks",
"description": "Binary data packing and unpacking.",
"version": "0.6.3",
"version": "0.6.5",
"homepage": "https://github.com/zswang/jpacks",
"authors": {
"name": "zswang",
Expand Down
22 changes: 20 additions & 2 deletions jpacks.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Binary data packing and unpacking.
* @author
* zswang (http://weibo.com/zswang)
* @version 0.6.3
* @date 2016-02-29
* @version 0.6.5
* @date 2016-03-01
*/
function createSchema() {
/**
Expand Down Expand Up @@ -1008,21 +1008,38 @@
fn.args = args;
});
Schema.register('enums', enums);
/*<function name="encodeUTF8">*/
/**
* 对字符串进行 utf8 编码
*
* param {string} str 原始字符串
'''<example>'''
* @example encodeUTF8():base
```js
console.log(jstrs.encodeUTF8('汉'));
// > 汉
```
'''</example>'''
*/
function encodeUTF8(str) {
if (/[\u0080-\uffff]/.test(str)) {
return unescape(encodeURIComponent(str));
}
return str;
}
/*</function>*/
/*<function name="decodeUTF8">*/
/**
* 对 utf8 字符串进行解码
*
* @param {string} str 编码字符串
'''<example>'''
* @example decodeUTF8():base
```js
console.log(jstrs.decodeUTF8('汉'));
// > 汉
```
'''</example>'''
*/
function decodeUTF8(str) {
if (/[\u00c0-\u00df][\u0080-\u00bf]/.test(str) ||
Expand All @@ -1031,6 +1048,7 @@
}
return str;
}
/*</function>*/
/**
* 将字符串转换为字节数组
*
Expand Down
22 changes: 20 additions & 2 deletions jpacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Binary data packing and unpacking.
* @author
* zswang (http://weibo.com/zswang)
* @version 0.6.3
* @date 2016-02-29
* @version 0.6.5
* @date 2016-03-01
*/
function createSchema() {
/**
Expand Down Expand Up @@ -945,21 +945,38 @@
fn.args = args;
});
Schema.register('enums', enums);
/*<function name="encodeUTF8">*/
/**
* 对字符串进行 utf8 编码
*
* param {string} str 原始字符串
'''<example>'''
* @example encodeUTF8():base
```js
console.log(jstrs.encodeUTF8('汉'));
// > 汉
```
'''</example>'''
*/
function encodeUTF8(str) {
if (/[\u0080-\uffff]/.test(str)) {
return unescape(encodeURIComponent(str));
}
return str;
}
/*</function>*/
/*<function name="decodeUTF8">*/
/**
* 对 utf8 字符串进行解码
*
* @param {string} str 编码字符串
'''<example>'''
* @example decodeUTF8():base
```js
console.log(jstrs.decodeUTF8('汉'));
// > 汉
```
'''</example>'''
*/
function decodeUTF8(str) {
if (/[\u00c0-\u00df][\u0080-\u00bf]/.test(str) ||
Expand All @@ -968,6 +985,7 @@
}
return str;
}
/*</function>*/
/**
* 将字符串转换为字节数组
*
Expand Down
Loading

0 comments on commit 8f1522f

Please sign in to comment.