|
@@ -47,30 +47,31 @@ export function guessElementSymbolTokens(tokens: Tokens, str: string, start: num
|
|
|
}
|
|
|
|
|
|
const reTrimSpacesAndNumbers = /^[\s\d]+|[\s\d]+$/g;
|
|
|
-export function guessElementSymbolString(str: string) {
|
|
|
+export function guessElementSymbolString(atomId: string, compId: string) {
|
|
|
// trim spaces and numbers, convert to upper case
|
|
|
- str = str.replace(reTrimSpacesAndNumbers, '').toUpperCase();
|
|
|
- const l = str.length;
|
|
|
+ atomId = atomId.replace(reTrimSpacesAndNumbers, '').toUpperCase();
|
|
|
+ const l = atomId.length;
|
|
|
|
|
|
- if (l === 0) return str; // empty
|
|
|
- if (l === 1) return str; // one char
|
|
|
+ if (l === 0) return atomId; // empty
|
|
|
+ if (l === 1) return atomId; // one char
|
|
|
|
|
|
if (l === 2) { // two chars
|
|
|
- if (str === 'NA' || str === 'CL' || str === 'FE' || str === 'SI' ||
|
|
|
- str === 'BR' || str === 'AS'
|
|
|
- ) return str;
|
|
|
+ if (atomId === 'NA' || atomId === 'CL' || atomId === 'FE' || atomId === 'SI' ||
|
|
|
+ atomId === 'BR' || atomId === 'AS'
|
|
|
+ ) return atomId;
|
|
|
}
|
|
|
|
|
|
- if (l === 3) { // three chars
|
|
|
- if (str === 'SOD') return 'NA';
|
|
|
- if (str === 'POT') return 'K';
|
|
|
- if (str === 'CES') return 'CS';
|
|
|
- if (str === 'CAL') return 'CA';
|
|
|
- if (str === 'CLA') return 'CL';
|
|
|
+ if (l === 3 && compId === atomId) { // three chars
|
|
|
+ if (atomId === 'SOD') return 'NA';
|
|
|
+ if (atomId === 'POT') return 'K';
|
|
|
+ if (atomId === 'CES') return 'CS';
|
|
|
+ if (atomId === 'CAL') return 'CA';
|
|
|
+ if (atomId === 'CLA') return 'CL';
|
|
|
}
|
|
|
|
|
|
- const c = str[0];
|
|
|
+ const c = atomId[0];
|
|
|
if (c === 'C' || c === 'H' || c === 'N' || c === 'O' || c === 'P' || c === 'S') return c;
|
|
|
|
|
|
return ''; // no reasonable guess, return empty string
|
|
|
-}
|
|
|
+}
|
|
|
+
|