-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -440,5 +440,36 @@ define(function () { | |
return ret; | ||
}; | ||
|
||
/** | ||
* 将"name:value[;name:value]"的属性值解析成Object | ||
* | ||
* @param {string} source 属性值源字符串 | ||
* @param {function=} 替换值的处理函数 | ||
* @return {Object} | ||
*/ | ||
lib.parseAttribute = function (source, valueReplacer) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
errorrik
via email
|
||
if (!source) { | ||
return {}; | ||
} | ||
|
||
var value = {}; | ||
var items = source.split(/\s*;\s*/); | ||
var len = items.length; | ||
|
||
while (len--) { | ||
var item = items[len]; | ||
if (!item) { | ||
continue; | ||
} | ||
|
||
var segment = item.split(/\s*:\s*/); | ||
value[segment[0]] = valueReplacer ? | ||
valueReplacer(segment[1]) | ||
: segment[1]; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
return lib; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parseAttribute不应该放在lib里吧?lib的定位是基础库适配,应该没有任何基础库会实现这种东西……