From a05053c9ac79d0a469329f4197073b890d4d9ae4 Mon Sep 17 00:00:00 2001
From: Walter Bender <walter@sugarlabs.org>
Date: Wed, 22 Dec 2010 21:23:59 -0500
Subject: [PATCH] converting-from-locale-fraction_sep-before-parsing
---
calculate.py | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/calculate.py b/calculate.py
index bda756c..1e4e529 100644
a
|
b
|
from svgimage import SVGImage |
48 | 48 | from decimal import Decimal |
49 | 49 | from rational import Rational |
50 | 50 | |
| 51 | def replace_fraction_seperator(text, fraction_sep): |
| 52 | ''' |
| 53 | Replace the fraction separator with '.' |
| 54 | A simple replace won't work, e.g. plot(x*x,x=-1,0..1,0) |
| 55 | ''' |
| 56 | |
| 57 | if fraction_sep == '.': |
| 58 | return text |
| 59 | |
| 60 | new_text = '' |
| 61 | parts = text.split(fraction_sep) |
| 62 | |
| 63 | for i in range(len(parts) - 1): |
| 64 | new_text += parts[i] |
| 65 | if new_text[-1] in string.digits and parts[i + 1][0] in string.digits: |
| 66 | new_text += '.' |
| 67 | else: |
| 68 | new_text += fraction_sep |
| 69 | |
| 70 | return new_text + parts[-1] |
| 71 | |
| 72 | |
51 | 73 | def findchar(text, chars, ofs=0): |
52 | 74 | ''' |
53 | 75 | Find a character in set <chars> starting from offset ofs. |
… |
… |
class Calculate(ShareableActivity): |
454 | 476 | s = unicode(self.text_entry.get_text()) |
455 | 477 | label = unicode(self.label_entry.get_text()) |
456 | 478 | _logger.debug('process(): parsing %r, label: %r', s, label) |
| 479 | s = replace_fraction_seperator(s, self.ml.fraction_sep) |
457 | 480 | try: |
458 | 481 | tree = self.parser.parse(s) |
459 | 482 | res = self.parser.evaluate(tree) |