Skip to content

Commit

Permalink
chore: Use FileUtils#readFileFromAssets in TextMateProvider to preven…
Browse files Browse the repository at this point in the history
…t duplication
  • Loading branch information
CyberGlitch01 committed Aug 20, 2023
1 parent 1358854 commit 52ed7b0
Showing 1 changed file with 2 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package editor.tsd.editors.sora.lang.textmate.provider;

import android.code.editor.common.utils.FileUtils;
import android.content.Context;
import android.content.res.AssetManager;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.github.rosemoe.sora.langs.textmate.registry.GrammarRegistry;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;

public class TextMateProvider {
Expand All @@ -22,28 +18,8 @@ public static String getLanguageScope(Context context, String fileExt) {
scopes =
new Gson()
.fromJson(
readFileFromAssets(context.getAssets(), "Editor/SoraEditor/language_scopes.json"),
FileUtils.readFileFromAssets(context.getAssets(), "Editor/SoraEditor/language_scopes.json"),
type);
return scopes.get(fileExt);
}

public static String readFileFromAssets(AssetManager assetManager, String fileName) {
StringBuilder stringBuilder = new StringBuilder();
try {
InputStream inputStream = assetManager.open(fileName);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append("\n");
}

bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}

return stringBuilder.toString();
}
}

1 comment on commit 52ed7b0

@SyntaxGalaxy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I forgot this one.

Please sign in to comment.