Closed Bug 173408 Opened 22 years ago Closed 22 years ago

Bug fix for Ethiopic Number Conversion Algorithm

Categories

(Core :: Internationalization, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: yacob, Assigned: smontagu)

Details

(Keywords: intl)

Attachments

(3 files, 3 obsolete files)

The existing algorithm in mozilla trips over certain cases where large numbers have big sequences of zeros and doesn't always remove superfluous '1's when it should. A patch is provided to fix this along with a test page.
Once applied this patch will need some tweaking. I don't know how the ns string class works and made some guesses. The routine adjustments are modelled after: http://www.ethiopic.org/Numerals/ArabicToEthiopic.c which implements the algorithm (recently updated) http://www.ethiopic.org/Numerals/
Attached file Tests for 90 numbers.
Some of these test case will probably fail just because the list item value overflows the data type used for integers.
==> internationalization
Assignee: dbaron → yokoyama
Component: Style System → Internationalization
QA Contact: ian → ruixu
Keywords: intl
QA Contact: ruixu → ylong
Status: UNCONFIRMED → NEW
Ever confirmed: true
Given that I don't actually understand the algorithm yet (I am discussing this with Daniel by e-mail) I don't think I should review it... at least not yet. :-)
This patch replaces the previous. It is identical except updated for todays nsBulletFrame.cpp.
Attachment #102295 - Attachment is obsolete: true
simon: would you look at the latest patch?
Assignee: yokoyama → smontagu
Comment on attachment 112414 [details] [diff] [review] Refreshed patch with 23/01/03 CVS snapshot >+ if ( (n % 2) == 0 ) { // number length was odd >+ // precondition the string to always have the leading tens place >+ // populated, this avoids a check within the loop: >+ >+ // I have no idea if this prefixing works, but you get the idea.. >+ asciiNumberString = (nsAutoString)"0" + asciiNumberString; >+ n++; >+ } asciiNumberString.Insert("0", 0) is the way to do this, but I think it would be more efficient to initialize asciiNumberString to "0" before the call to DecimalToText() and then use the substring from 1 to the end if the length of the string is odd. >+ for (PRInt32 place = n; place >= n; place--) { This should be place >= 0, no? >+ PRUnichar asciiTen = asciiNumberString.CharAt(n-place--); >+ PRUnichar asciiOne = asciiNumberString.CharAt(n-place); Now I'm confused. Are you iterating from highest digit to lowest digit or from lowest to highest? The first version of the patch has a comment + // Iterate from the highest digit to lowest digit but this version keeps the original comment // Iterate from the lowest digit to higher digits If you are going from high to low, please change the comment. >+ // pos indicates if our grouping subscript is even or odd >+ PRInt32 pos = (place % 4) / 2; >+ >+ // find a separator, if any, to follow Ethiopic ten and one >+ PRUnichar sep >+ = ( place ) >+ ? ( pos ) >+ ? ( ethioOne || ethioTen ) >+ ? (PRUnichar) 0x137B >+ : 0x0 >+ : (PRUnichar) 0x137C >+ : 0x0 >+ ; ethioOne and ethioTen are used here before they are defined. Triple nesting of [? :] ternaries is going too far, IMO. >+ // map onto Ethiopic "tens": U+1372=Ethiopic number ten >+ ethioTen = (PRUnichar) ((PRInt32) asciiTen + 0x1372 - 0x31); >+ } >+ if (asciiOne > '0') >+ { >+ //map onto Ethiopic "ones": 0x1369=Ethiopic digit one >+ ethioOne = (PRUnichar) ((PRInt32) asciiOne + 0x1369 - 0x31); Use #defined constants instead of the hardcoded numbers (and maybe also instead of the hardcoded literal '0' and '1'). Nit: "tens" and "units" is better English than "tens" and "ones". >+ result.Insert(ethioNumber, 0); If you are going from highest digit to lowest, then you want to use Append(), not Insert().
Attachment #112414 - Flags: review-
This patch should contain all of the suggestions made by simon. Please review to see that I have understood the suggestions as intended.
Attachment #112414 - Attachment is obsolete: true
I had to make a few changes to make the patch compile, and while I was at it I made the names more descriptive, and made the logic a bit clearer, at least in my eyes. One of my earlier comments was wrong: it doesn't work to initialize asciiNumberString to "0", because we then get the leading zero for values where we bail out of the algorithm, e.g. "0-1" for -1. The testcases all seem to work now, except when the values overflow.
Attachment #125521 - Attachment is obsolete: true
The testcase is too large for a screenshot. I hope a .pdf will work.
Simon, it looks really super! I'll print and examine the list carefully. On the overflow issue, what is the highest number that mozilla can handle in lists?
>what is the highest number that mozilla can handle in lists? The list index is passed around in a PRInt32, so the maximum value is 2147483647 (0x7FFFFFFF)
Comment on attachment 125863 [details] [diff] [review] Simplified version r=smontagu (I attached this, but it's in effect Daniel's patch incorporating my review comments). jag, can you sr?
Attachment #125863 - Flags: superreview?(jaggernaut)
Attachment #125863 - Flags: review+
Comment on attachment 125863 [details] [diff] [review] Simplified version sr=jag
Attachment #125863 - Flags: superreview?(jaggernaut) → superreview+
Fix checked in.
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Comment on attachment 102295 [details] [diff] [review] cvs diff -u against nsBulletFrame.cpp clearing obsolete review request
Attachment #102295 - Flags: review?(ian)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: