From 33fe781e18fbbcbfb9741427ff64c9b93c63228d Mon Sep 17 00:00:00 2001 From: baolan2005 Date: Fri, 4 Feb 2022 22:45:26 +0100 Subject: [PATCH] fixed bugs and release version 0.0.5 --- .../com/baolan2005/jcampconverter/Jcamp.kt | 29 ++++++++----------- ...test_file_10_failed.dx => test_file_10.dx} | 0 .../baolan2005/jcampconverter/MainActivity.kt | 2 +- 3 files changed, 13 insertions(+), 18 deletions(-) rename JcampConverter/app/src/main/assets/testdata/{test_file_10_failed.dx => test_file_10.dx} (100%) diff --git a/JcampConverter/JcampConverter/src/main/java/com/baolan2005/jcampconverter/Jcamp.kt b/JcampConverter/JcampConverter/src/main/java/com/baolan2005/jcampconverter/Jcamp.kt index 67edbbc..9147dd8 100644 --- a/JcampConverter/JcampConverter/src/main/java/com/baolan2005/jcampconverter/Jcamp.kt +++ b/JcampConverter/JcampConverter/src/main/java/com/baolan2005/jcampconverter/Jcamp.kt @@ -307,20 +307,17 @@ class Jcamp { private fun scanner(strVal: String): ArrayList { var result = ArrayList() - var tmpStr = "" - val scanStr = strVal var startPoint = -1 - for ((idx, c) in scanStr.withIndex()) { - if (idx == startPoint-1) { + for ((idx, c) in strVal.withIndex()) { + if (idx == startPoint - 1) { continue } if (c.isNumberic() || c.equals('.', true)) { tmpStr = tmpStr.plus(c) - } - else { + } else { if (tmpStr != "") { tmpStr = tmpStr.trim() result.add(tmpStr) @@ -330,10 +327,10 @@ class Jcamp { val charString = c.toString() if (Constants.DUP.containsKey(charString)) { var nextChars = "" - if (idx < scanStr.length - 1) { - startPoint = idx+1 - while (scanStr[startPoint].isNumberic()) { - nextChars = nextChars.plus(scanStr[idx+1]) + if (idx < strVal.length - 1) { + startPoint = idx + 1 + while (strVal[startPoint].isNumberic()) { + nextChars = nextChars.plus(strVal[idx + 1]) startPoint += 1 } } @@ -341,24 +338,22 @@ class Jcamp { val strDupValFull = "%d%s".format(Locale.getDefault(), dupVal, nextChars) var dupValInt: Int = dupVal try { - strDupValFull.toInt() - } - catch (e: Exception) { + dupValInt = strDupValFull.toInt() + } catch (e: Exception) { } //Check DUP for (i in 0 until dupValInt-1) { val lastTmpStr = result.last() +// Log.d("baolanlequang", lastTmpStr) if (!lastTmpStr.isNullOrEmpty()) { result.add(lastTmpStr) } } - } - else if (Constants.SQZ.containsKey(charString)) { + } else if (Constants.SQZ.containsKey(charString)) { val sqzVal = Constants.SQZ[charString] tmpStr = tmpStr.plus(sqzVal) - } - else { + } else { tmpStr = tmpStr.plus(c) } } diff --git a/JcampConverter/app/src/main/assets/testdata/test_file_10_failed.dx b/JcampConverter/app/src/main/assets/testdata/test_file_10.dx similarity index 100% rename from JcampConverter/app/src/main/assets/testdata/test_file_10_failed.dx rename to JcampConverter/app/src/main/assets/testdata/test_file_10.dx diff --git a/JcampConverter/app/src/main/java/com/baolan2005/jcampconverter/MainActivity.kt b/JcampConverter/app/src/main/java/com/baolan2005/jcampconverter/MainActivity.kt index 49013cd..26e4e04 100644 --- a/JcampConverter/app/src/main/java/com/baolan2005/jcampconverter/MainActivity.kt +++ b/JcampConverter/app/src/main/java/com/baolan2005/jcampconverter/MainActivity.kt @@ -9,7 +9,7 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - val input = assets.open("testdata/test_file_10_failed.dx") + val input = assets.open("testdata/test_file_20.dx") val reader = JcampReader(input) val jcamp = reader.jcamp