Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge: ``proper quotes''

Name: Anonymous 2008-08-12 20:08

Write a program that takes a text file and converts adirectional quotes into `` and '', i.e.

INPUT:
I turned my head around, with that casual smile all over my face.
"The stuff you said in your intro, how much of it was serious?"
With her arms crossed in front of her chest, lips sealed tight,
Suzumiya Haruhi kept her stern posture, staring right into my eyes.
"What 'stuff in my intro?'"
"The stuff about the aliens and all that."
"Are you an alien?"


OUTPUT:
I turned my head around, with that casual smile all over my face.
``The stuff you said in your intro, how much of it was serious?''
With her arms crossed in front of her chest, lips sealed tight,
Suzumiya Haruhi kept her stern posture, staring right into my eyes.
``What 'stuff in my intro?'''
``The stuff about the aliens and all that.''
``Are you an alien?''


Use whatever language you want. Bonus points for creativity and efficiency.

I'll start:
#include <stdio.h>

char *q[]= {"''", "``"};
main() {
 int c, i=0;
 while((c=getchar())!=EOF) {
  if(c=='"')
   printf("%s",q[i^=1]);
  else
   putchar(c);
 }
}

Name: Anonymous 2008-08-13 11:44

>>21
Another Haskell version, just for the hell of it.


properQuotes str = properQuotes' str False
  where
    properQuotes' []       _     = []
    properQuotes' ('"':cs) False = "``" ++ properQuotes' cs True
    properQuotes' ('"':cs) True  = "''" ++ properQuotes' cs False
    properQuotes' (c:cs)   quote = c : properQuotes' cs quote

main = interact $ properQuotes

Name: Anonymous 2008-08-13 12:02

main = interact $ fixQuotes "``" "''"
   where
      fixQuotes _ _ [] = []
      fixQuotes open close ('"': text) = open ++ fixQuotes close open text
      fixQuotes open close (c: text) = c: fixQuotes open close text

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List