Subversion Repositories JSX

Compare Revisions

Last modification

Ignore whitespace Rev 499 → Rev 500

/trunk/UniCalc/unicalc.js
0,0 → 1,150
function toASCII (unicode)
{
var ascii = new jsx.regexp.String(unicode.value).replace(
jsx.regexp.RegExp(
"(?<operand>[−×∕])|(?<root>[√])|(?<delim>'+)"
+ "|(?<exponent>[⁰¹²³\u2074-\u2079⁺⁻⁽⁾]+)"
+ "|\\b(?<const>g)\\b",
"g"),
function (match) {
var groups = this.groups;
if (groups["operand"])
{
switch (match)
{
case "−": return "-";
case "×": return "*";
case "∕": return "/";
}
}
 
if (groups["root"])
{
switch (match)
{
case "√": return "sqrt";
default:
return match;
}
}
 
if (groups["delim"])
{
return "";
}
 
if (groups["exponent"])
{
var exponent = match.replace(
/./g,
function (match) {
switch (match)
{
case "⁰": return "0";
case "¹": return "1";
case "²": return "2";
case "³": return "3";
case "⁺": return "+";
case "⁻": return "-";
case "⁼": return "=";
case "⁽": return "(";
case "⁾": return ")";
default:
if (/[\u2074-\u2079]/.test(match))
{
return String.fromCharCode(
0x30 + (match.charCodeAt(0) - 0x2070));
}
 
return match;
}
});
 
return "^(" + exponent + ")";
}
 
if (groups["const"])
{
switch (match)
{
case "g": return "9.81 m/s^2";
}
}
 
return match;
});
 
unicode.form.elements["q"].value = ascii;
}
 
function toUnicode (ascii)
{
var unicode = new jsx.regexp.String(ascii.value).replace(
jsx.regexp.RegExp(
"(?<operand>[-*/])|\\b(?<root>(sq|cub)rt)\\b|\\^(?<exponent>[\\d()]+)",
"g"),
function (match) {
var groups = this.groups;
if (groups["operand"])
{
return jsx.object.getProperty({
"-": "−",
"*": "×",
"/": "∕"
}, match);
}
 
if (groups["root"])
{
switch (match)
{
case "cubrt": return "∛";
case "sqrt": return "√";
default:
return match;
}
}
 
if (groups["exponent"])
{
var exponent = groups["exponent"].replace(
/./g,
function (match) {
switch (match)
{
case "0": return "⁰";
case "1": return "¹";
case "2": return "²";
case "3": return "³";
case "+": return "⁺";
case "-": return "⁻";
case "=": return "⁼";
case "(": return "⁽";
case ")": return "⁾";
default:
if (/[4-9]/.test(match))
{
return String.fromCharCode(
match.charCodeAt(0) - 0x30 + 0x2070);
}
 
return match;
}
});
 
return exponent;
}
 
return match;
});
 
ascii.form.elements["unicode"].value = unicode;
}
 
function calc (form)
{
return !window.open(
form.action + "?q=" + encodeURIComponent(form.elements["q"].value),
form.target,
"width=720,height=630,resizable");
}
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: trunk/UniCalc/index.html
===================================================================
--- trunk/UniCalc/index.html (nonexistent)
+++ trunk/UniCalc/index.html (revision 500)
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8">
+ <title>UniCalc (Unicode Calculator) — PointedEars’ Website</title>
+ <style type="text/css">
+ <!--
+ table {
+ width: 100%;
+ }
+
+ th {
+ width: 8em;
+ text-align: right;
+ }
+
+ th:after {
+ content: ":";
+ }
+
+ [lang^="fr"] th:after {
+ content: "\00A0 :";
+ }
+
+ .td3 {
+ width: 8em;
+ }
+
+ input {
+ width: 100%;
+ }
+ -->
+ </style>
+ <script type="text/javascript" src="../builder?src=object,regexp"></script>
+ <script type="text/javascript" src="unicalc.js"></script>
+ </head>
+ <body>
+ <h1>UniCalc – Unicode Calculator</h1>
+ <form action="http://www.google.com/search" target="result"
+ onsubmit="return calc(this)">
+ <table>
+ <tr>
+ <th><label for="unicode">Unicode <u>f</u>ormula</label></th>
+ <td><input type="search" id="unicode" name="unicode" accesskey="f"
+ onkeyup="toASCII(this)"
+ oninput="toASCII(this)"
+ ></td>
+ </tr>
+ <tr>
+ <th><label for="ascii"><u>A</u>SCII formula</label></th>
+ <td><input type="search" id="ascii" name="q" accesskey="a"
+ onkeyup="toUnicode(this)"
+ oninput="toUnicode(this)"
+ ></td>
+ <td class="td3"><input type="submit" value="Calculate (Google)"></td>
+ </tr>
+ </table>
+ </form>
+ </body>
+</html>
/trunk/UniCalc/index.html
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property