fucketh1cs

[prg] String to Poop 1.0 converter

Nov 7th, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.25 KB | None | 0 0
  1. /*
  2.  * String to Poop 1.0 Converter
  3.  * @author Maximilian Krause
  4.  * @since 11-07-2015
  5.  * @ver 1.1
  6.  *
  7.  * Changelog
  8.  * 1.1
  9.  * - Added uppercase/lowercase output through char uppercase detection
  10.  *
  11.  * This converter is capable of getting a String from a file and outputting the equivalent for Poop 1.0. Due to Poops limits, the Poop 1.0 output will not support spaces but will write every word into a new line.
  12.  *
  13.  * Licensed under CC-BY 4.0.
  14.  */
  15. package de.maxkrause;
  16. //importing needed tools
  17. import java.io.*;
  18. import java.util.Scanner;
  19.  
  20. public class main {
  21.     static boolean debug = false; //debug bool, activate if you want debug output
  22.     public static void main(String[] args) {
  23.         System.out.println("String to Poop 1.0 Translator, made by Maximilian Krause. Licensed under CC-BY 4.0. Please input a file without any new-lines. Change new-lines to spaces if needed. Poop 1.0 doesn't support new-lines, every new word will get into a new line anyway.");;
  24.         Scanner in = new Scanner(System.in); //opening a scanner to get the input filename
  25.         //setting some needed, accessible vars
  26.         int curIndex = 0;
  27.         String chars = "0123456789abcdefghijklmnopqrstuvwxyz.,-!?+*<>#@$โ‚ฌยง%&/()[]"; //Poop 1.0 supported characters
  28.         String input = "";
  29.         String output = "";
  30.         boolean gotFile = false;
  31.         String str_input_file = "";
  32.         while(!gotFile){ //always asking for input until a valid file was opened
  33.             System.out.print("File with content to translate: ");
  34.             str_input_file = in.next();
  35.             try {
  36.                 Scanner input_file = new Scanner(new FileReader(str_input_file)); //opening a new scanner to get the file content
  37.                 input = input_file.nextLine(); //reading the file content into input
  38.                 gotFile = true; //closing the loop
  39.                 //closing the scanners
  40.                 input_file.close();
  41.                 in.close();
  42.                 while(input.endsWith(" ")){
  43.                     input = input.substring(0, input.length()-2); //removing a last space if found
  44.                 }
  45.                 System.out.println("Got input: " + input);
  46.             } catch (FileNotFoundException e) {
  47.                 System.out.println("File not found."); //file not found, looping back
  48.             }
  49.         }
  50.         System.out.println("Now calculating. Please wait...");
  51.         for(int i = 0; (input.length()) > i; i++){ //starting calculation process
  52.             if(debug){
  53.                 System.out.println("[DEBUG] Now checking character #" + i + ", which is " + input.charAt(i) + ", which got the Poop index #" + chars.indexOf(input.toLowerCase().charAt(i)));
  54.             }
  55.             if(input.charAt(i) == ' '){ //checking if current character is a space
  56.                 if(debug){
  57.                     System.out.println("Received a space character, printing sniff\\nflush\\n.");
  58.                 }
  59.                 output += "sniff\nflush\n"; //if so, doing a "sniff" and a "flush" to print the last word
  60.                 curIndex = 0; //resetting the current Poop 1.0 character index, as flush does so as well
  61.             }else{
  62.                 boolean isPuke = false;
  63.                 if(debug){
  64.                     System.out.println("[DEBUG] Previous index: " + curIndex);
  65.                 }
  66.                 int eats = chars.indexOf(input.toLowerCase().charAt(i)) - curIndex;
  67.                 curIndex = chars.indexOf(input.toLowerCase().charAt(i));
  68.                 if(debug){
  69.                     System.out.println("[DEBUG] Got the command for " + eats + " eats, checking if I should puke.");
  70.                 }
  71.                 if(eats < 0){
  72.                     //eats is negative, which means that we need to go back on the Poop 1.0 index -> puke instead of eat
  73.                     eats = eats * -1;
  74.                     if(debug){
  75.                         System.out.println("[DEBUG] Puking " + curIndex + " times.");
  76.                     }
  77.                     isPuke = true;
  78.                 }
  79.                 //printing the needed times of eat or puke
  80.                 if(isPuke){
  81.                     output += new String(new char[eats]).replace("\0", "puke ");
  82.                 }else{
  83.                     output += new String(new char[eats]).replace("\0", "eat ");
  84.                 }
  85.                 //checking if we needed an uppercase letter
  86.                 if(Character.isUpperCase(input.charAt(i))){
  87.                     output += "\nPOOP\n";
  88.                 }else{
  89.                     output += "\npoop\n";
  90.                 }
  91.             }
  92.         }
  93.         //last String output
  94.         output += "sniff";
  95.         //writing to output file (input + "_poo")
  96.         Writer writer = null;
  97.         try {
  98.             writer = new BufferedWriter(new OutputStreamWriter(
  99.                   new FileOutputStream(str_input_file + "_poo"), "utf-8"));
  100.             writer.write(output);
  101.         } catch (IOException ex) {} finally {
  102.            try {writer.close();} catch (Exception ex) {}
  103.         }
  104.         System.out.println("Output written to " + str_input_file + "_poo.");
  105.     }
  106.  
  107. }
Add Comment
Please, Sign In to add comment