<commit_before>package stringparser;

/**
 * Author : Julien
 * Date : 04/11/13, 9:02 AM
 * Copyright (c) 2014 <NAME>. All rights reserved.
 */

import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.io.CsvBeanReader;
import org.supercsv.prefs.CsvPreference;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class StringParser{
    //Config Variables
    private static String url = null;
    private static String englishPath = null;
    private static String frenchPath = null;

    //Platforms
    private static int platform = -1;
    private static final int ANDROID = 0;
    private static final int IOS = 1;
    private static final int WINDOWS = 2;

    //Stuff from the file
    private static final String URL = "URL:";
    private static final String PLATFORM = "Platform:";
    private static final String ANDROID_ENGLISH = "Android English Path:";
    private static final String ANDROID_FRENCH = "Android French Path:";
    private static final String IOS_ENGLISH = "iOS English Path:";
    private static final String IOS_FRENCH = "iOS French Path:";
    private static final String WINDOWS_ENGLISH = "Windows English Path:";
    private static final String WINDOWS_FRENCH = "Windows French Path:";

    //Writers
    private static PrintWriter englishWriter;
    private static PrintWriter frenchWriter;

    //To keep track of which line number you are at
    private static int lineNumber;

    public static void main(String[] args) throws IOException {
        //Read from the config file
        BufferedReader configReader;
        try{
            configReader = new BufferedReader(new FileReader("../config.txt"));
        }
        catch(FileNotFoundException e){
            configReader = new BufferedReader(new FileReader("config.txt"));
        }

        String line;
        while ((line = configReader.readLine()) != null) {

            //Get the Docs URL
            if(line.startsWith(URL)){
                url = line.replace(URL, "").trim();
            }

            //Get the platform
            else if(line.startsWith(PLATFORM)){
                String platformString = line.replace(PLATFORM, "").trim();
                if(platformString.equalsIgnoreCase("android")){
                    platform = ANDROID;
                }
                else if(platformString.equalsIgnoreCase("ios")){
                    platform = IOS;
                }
                else if(platformString.equalsIgnoreCase("windows")){
                    platform = WINDOWS;
                }
                else{
                    System.out.println("Error: Platform must be either Android, iOS, or Windows.");
                }
            }

            //Get the path for the file.
            else if(platform == ANDROID && line.startsWith(ANDROID_ENGLISH)){
                englishPath = line.replace(ANDROID_ENGLISH, "").trim();
            }
            else if(platform == ANDROID && line.startsWith(ANDROID_FRENCH)){
                frenchPath = line.replace(ANDROID_FRENCH, "").trim();
            }
            else if(platform == IOS && line.startsWith(IOS_ENGLISH)){
                englishPath = line.replace(IOS_ENGLISH, "").trim();
            }
            else if(platform == IOS && line.startsWith(IOS_FRENCH)){
                frenchPath = line.replace(IOS_FRENCH, "").trim();
            }
            else if(platform == WINDOWS && line.startsWith(WINDOWS_ENGLISH)){
                englishPath = line.replace(WINDOWS_ENGLISH, "").trim();
            }
            else if(platform == WINDOWS&& line.startsWith(WINDOWS_FRENCH)){
                frenchPath = line.replace(WINDOWS_FRENCH, "").trim();
            }
        }
        configReader.close();

        //Make sure nothing is null
        if(url == null){
            System.out.println("Error: URL Cannot be null");
            System.exit(0);
        }
        else if(platform == -1){
            System.out.println("Error: You need to input a platform");
            System.exit(0);
        }
        else if(englishPath == null){
            System.out.println("Error: You need to input a path for the english strings");
            System.exit(0);
        }
        else if(frenchPath == null){
            System.out.println("Error: You need to input a path for the french strings");
            System.exit(0);
        }

        //Set up the writers
        englishWriter = new PrintWriter(englishPath, "UTF-8");
        frenchWriter = new PrintWriter(frenchPath, "UTF-8");

        //Connect to the URL
        URL link = new URL(url);
        HttpURLConnection httpConnection = (HttpURLConnection) link.openConnection();
        httpConnection.setRequestMethod("GET");
        httpConnection.connect();

        //Parse the strings
        List<Strings> strings = new ArrayList<Strings>();
        CsvBeanReader reader = new CsvBeanReader(new InputStreamReader(httpConnection.getInputStream()), CsvPreference.EXCEL_PREFERENCE);

        try {
            final String[] header = reader.getHeader(true);
            final CellProcessor[] processors = getProcessors();

            Strings currentLine;
            while( (currentLine = reader.read(Strings.class, header, processors)) != null){
                strings.add(currentLine);
            }
            if(!strings.isEmpty()){
                processStrings(strings);
            }
        }
        finally {
            reader.close();
        }
    }

    public static CellProcessor[] getProcessors(){
        return new CellProcessor[]{
                null,
                null,
                null,
                null,
        };
    }

    public static void processStrings(List<Strings> strings)throws FileNotFoundException, UnsupportedEncodingException{
        if(platform == ANDROID){
            processAndroidStrings(strings);
        }
        else if(platform == IOS){
            processIOSStrings(strings);
        }
        else{
            processWindowsStrings(strings);
        }
    }

    /**
     * Processes a given String with the common changes to make between Android and iOS
     *
     * @param string The String to process
     */
    private static String processString(String string){
        //Unescaped quotations
        string = string.replace(" \"", " \\" + "\"");

        //Copyright
        string = string.replace("(c)", "\u00A9");

        return string;
    }

    /** ANDROID STRING PARSING **/
    //Stuff for Android Strings
    public static final String XML_OPENER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
    public static final String RESOURCES_OPENER = "<resources>";
    public static final String RESOURCES_CLOSER = "</resources>";

    public static void processAndroidStrings(List<Strings> strings)throws FileNotFoundException, UnsupportedEncodingException{
        //Add the XML header for Android files
        englishWriter.println(XML_OPENER);
        frenchWriter.println(XML_OPENER);
<commit_msg>Went back to the old times.<commit_after>package stringparser;

/**
 * Author : Julien
 * Date : 04/11/13, 9:02 AM
 * Copyright (c) 2014 <NAME>. All rights reserved.
 */

import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.io.CsvBeanReader;
import org.supercsv.prefs.CsvPreference;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class StringParser{
    //Config Variables
    private static String url = null;
    private static String englishPath = null;
    private static String frenchPath = null;

    //Platforms
    private static int platform = -1;
    private static final int ANDROID = 0;
    private static final int IOS = 1;
    private static final int WINDOWS = 2;

    //Stuff from the file
    private static final String URL = "URL:";
    private static final String PLATFORM = "Platform:";
    private static final String ANDROID_ENGLISH = "Android English Path:";
    private static final String ANDROID_FRENCH = "Android French Path:";
    private static final String IOS_ENGLISH = "iOS English Path:";
    private static final String IOS_FRENCH = "iOS French Path:";
    private static final String WINDOWS_ENGLISH = "Windows English Path:";
    private static final String WINDOWS_FRENCH = "Windows French Path:";

    //Writers
    private static PrintWriter englishWriter;
    private static PrintWriter frenchWriter;

    //To keep track of which line number you are at
    private static int lineNumber;

    public static void main(String[] args) throws IOException {
        //Read from the config file
        BufferedReader configReader;
        try{
            configReader = new BufferedReader(new FileReader("../config.txt"));
        }
        catch(FileNotFoundException e){
            configReader = new BufferedReader(new FileReader("config.txt"));
        }

        String line;
        while ((line = configReader.readLine()) != null) {

            //Get the Docs URL
            if(line.startsWith(URL)){
                url = line.replace(URL, "").trim();
            }

            //Get the platform
            else if(line.startsWith(PLATFORM)){
                String platformString = line.replace(PLATFORM, "").trim();
                if(platformString.equalsIgnoreCase("android")){
                    platform = ANDROID;
                }
                else if(platformString.equalsIgnoreCase("ios")){
                    platform = IOS;
                }
                else if(platformString.equalsIgnoreCase("windows")){
                    platform = WINDOWS;
                }
                else{
                    System.out.println("Error: Platform must be either Android, iOS, or Windows.");
                }
            }

            //Get the path for the file.
            else if(platform == ANDROID && line.startsWith(ANDROID_ENGLISH)){
                englishPath = line.replace(ANDROID_ENGLISH, "").trim();
            }
            else if(platform == ANDROID && line.startsWith(ANDROID_FRENCH)){
                frenchPath = line.replace(ANDROID_FRENCH, "").trim();
            }
            else if(platform == IOS && line.startsWith(IOS_ENGLISH)){
                englishPath = line.replace(IOS_ENGLISH, "").trim();
            }
            else if(platform == IOS && line.startsWith(IOS_FRENCH)){
                frenchPath = line.replace(IOS_FRENCH, "").trim();
            }
            else if(platform == WINDOWS && line.startsWith(WINDOWS_ENGLISH)){
                englishPath = line.replace(WINDOWS_ENGLISH, "").trim();
            }
            else if(platform == WINDOWS&& line.startsWith(WINDOWS_FRENCH)){
                frenchPath = line.replace(WINDOWS_FRENCH, "").trim();
            }
        }
        configReader.close();

        //Make sure nothing is null
        if(url == null){
            System.out.println("Error: URL Cannot be null");
            System.exit(0);
        }
        else if(platform == -1){
            System.out.println("Error: You need to input a platform");
            System.exit(0);
        }
        else if(englishPath == null){
            System.out.println("Error: You need to input a path for the english strings");
            System.exit(0);
        }
        else if(frenchPath == null){
            System.out.println("Error: You need to input a path for the french strings");
            System.exit(0);
        }

        //Set up the writers
        englishWriter = new PrintWriter(englishPath, "UTF-8");
        frenchWriter = new PrintWriter(frenchPath, "UTF-8");

        //Connect to the URL
        URL link = new URL(url);
        HttpURLConnection httpConnection = (HttpURLConnection) link.openConnection();
        httpConnection.setRequestMethod("GET");
        httpConnection.connect();

        //Parse the strings
        List<Strings> strings = new ArrayList<Strings>();
        CsvBeanReader reader = new CsvBeanReader(new InputStreamReader(httpConnection.getInputStream()), CsvPreference.EXCEL_PREFERENCE);

        try {
            final String[] header = reader.getHeader(true);
            final CellProcessor[] processors = getProcessors();

            Strings currentLine;
            while( (currentLine = reader.read(Strings.class, header, processors)) != null){
                strings.add(currentLine);
            }
            if(!strings.isEmpty()){
                processStrings(strings);
            }
        }
        finally {
            reader.close();
        }
    }

    public static CellProcessor[] getProcessors(){
        return new CellProcessor[]{
                null,
                null,
                null,
                null,
        };
    }

    public static void processStrings(List<Strings> strings)throws FileNotFoundException, UnsupportedEncodingException{
        if(platform == ANDROID){
            processAndroidStrings(strings);
        }
        else if(platform == IOS){
            processIOSStrings(strings);
        }
        else{
            processWindowsStrings(strings);
        }
    }

    /**
     * Processes a given String with the common changes to make between Android and iOS
     *
     * @param string The String to process
     */
    private static String processString(String string){
        //Unescaped quotations
        string = string.replace("\"", "\\" + "\"");

        //Copyright
        string = string.replace("(c)", "\u00A9");

        return string;
    }

    /** ANDROID STRING PARSING **/
    //Stuff for Android Strings
    public static final String XML_OPENER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
    public static final String RESOURCES_OPENER = "<resources>";
    public static final String RESOURCES_CLOSER = "</resources>";

    public static void processAndroidStrings(List<Strings> strings)throws FileNotFoundException, UnsupportedEncodingException{
        //Add the XML header for Android files
        englishWriter.println(XML_OPENER);
        frenchWriter.println(XML_OPENER);

{'fraction_non_alphanumeric': 0.10450616409239054, 'fraction_numerical': 0.0042510982003684285, 'mean_word_length': 2.0987925356750825, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 2, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2251658', 'n_tokens_mistral': 3819, 'n_tokens_neox': 3659, 'n_words': 1007}