From 3cf3cf1000ce6b27ac622c75fc3d114874e2f3a8 Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Fri, 29 Sep 2006 22:27:02 +0000 Subject: code beauty: moved some code into util.js git-svn-id: http://svn.klever.net/kin/fireflix/trunk@168 fe716a7a-6dde-0310-88d9-d003556173a8 --- (limited to 'content/util.js') diff --git a/content/util.js b/content/util.js new file mode 100644 index 0000000..5af0978 --- a/dev/null +++ b/content/util.js @@ -0,0 +1,61 @@ +/* + * convert unicode string to utf-8 representation. + * needed for correct md5 hash calculation. + */ +function toutf8(ucode) { + var rv = ''; + for(var i=0;i> 6)&0x1f), + 0x80|( cc &0x3f) ); + else if(cc<=0xffff) + rv += String.fromCharCode( + 0xe0|((cc>>12)&0x0f), + 0x80|((cc>> 6)&0x3f), + 0x80|( cc &0x3f) ); + else if(cc<=0x1fffff) + rv += String.fromCharCode( + 0xf0|((cc>>18)&0x07), + 0x80|((cc>>12)&0x3f), + 0x80|((cc>> 6)&0x3f), + 0x80|( cc &0x3f) ); + else if(cc<=0x03ffffff) + rv += String.fromCharCode( + 0xf8|((cc>>24)&0x03), + 0x80|((cc>>18)&0x3f), + 0x80|((cc>>12)&0x3f), + 0x80|((cc>> 6)&0x3f), + 0x80|( cc &0x3f) ); + else if(cc<=0x7fffffff) + rv += String.fromCharCode( + 0xfc|((cc>>30)&0x01), + 0x80|((cc>>24)&0x3f), + 0x80|((cc>>18)&0x3f), + 0x80|((cc>>12)&0x3f), + 0x80|((cc>> 6)&0x3f), + 0x80|( cc &0x3f) ); + } + return rv; +} + +/* + * extract xpath-specified string value + */ +function xp_str(xp,x) { + var rv = x.evaluate( + xp, x, null, XPathResult.STRING_TYPE, null ); + return rv.stringValue; +} +/* + * extract xpath-specified node + */ +function xp_node(xp,x) { + var rv = x.evaluate( + xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); + return rv.singleNodeValue; +} + -- cgit v0.9.0.2