Skip to content

Commit

Permalink
Corrected wrong translation
Browse files Browse the repository at this point in the history
  • Loading branch information
landicami committed Oct 31, 2024
1 parent 5a98dc9 commit b287e61
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/utils/translator/braillePhraseToNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,38 @@ import { mapBrailleToNumber, numberSign, stopSign } from "../../data/MapBrailleT
* @param {string} braillePhrase - The Braille text to be converted.
* @param {number} currentIndex - The current index in the Braille text.
* @returns {string|undefined} The converted number if found, otherwise undefined.
*
*/
export default function braillePhraseToNumber(braillePhrase, currentIndex) {

// Check if the current character is a number sign
if (braillePhrase.charAt(currentIndex) === numberSign) {

let numberString = ""
let numberString = "";
let previousCharWasDash = false; // Flag to check if the last character was a dash

for (let i = currentIndex + 1; i < braillePhrase.length; i++) {

let currentChar = braillePhrase.charAt(i)

if (currentChar === stopSign) break // End the number conversion

const number = brailleCharToNumber(currentChar)

if (number === undefined) break // End the number conversion

// TODO: OR check if . or ,

numberString += number
let currentChar = braillePhrase.charAt(i);

if (currentChar === stopSign) break; // End the number conversion

if (currentChar === "⠤") {
// If currentChar is a dash and the previous one was not, add a single dash
if (!previousCharWasDash) {
numberString += "-"; // Add a dash only if the last character was not a dash
previousCharWasDash = true; // Set the flag to true
}
} else {
const number = brailleCharToNumber(currentChar);
if (number === undefined) break; // End the number conversion if non-numeric character is encountered

numberString += number; // Append the number to the result
previousCharWasDash = false; // Reset the flag since we just added a number
}
}
return numberString

return numberString.trim(); // Trim to remove any unnecessary whitespace
} else {
return undefined // If the current character is not a number sign, return undefined
return undefined; // If the current character is not a number sign, return undefined
}
}

function brailleCharToNumber(brailleChar) {
return mapBrailleToNumber[brailleChar]
return mapBrailleToNumber[brailleChar];
}

0 comments on commit b287e61

Please sign in to comment.