Problem Statement
We want to write a chat parser that will remove all of the "smilies" from some text to make it more professional.
A "smilie" is defined as a character representing a pair of eyes, one of ':', ';', '8', or 'B', followed by an OPTIONAL nose, one of '-', 'o', '*', or '^', and finally a mouth, one of 'P', ')', '(', '[', or ']'.
For example, ":)", ";-]", "8[", "8*P", and "B^(" are all smilies, but
"X(" is not a smilie (invalid eyes)
":-" is not a smilie (no mouth)
"8v)" is not a smilie (invalid nose)
Given a
Definition
- Class:
- ChatParser
- Method:
- deSmilie
- Parameters:
- String
- Returns:
- String
- Method signature:
- String deSmilie(String text)
- (be sure your method is public)
Notes
- zero, '0', and capital oh, 'O', are not valid noses; only '-', 'o' (lowercase oh), '*', and '^' are valid noses.
- all leading, trailing, and internal spaces should appear exactly in the return String as they do in the input String.
- there will be no internal spaces in a smilie. i.e., ": - )" isn't a smilie.
- do not recursively check for smilies, i.e., only do one pass. "::-))" should return ":)".
Constraints
- text is between 0 and 50 characters, inclusive.
- text will consist only of the characters 'A'-'Z', 'a'-'z', '0'-'9', spaces, and "-^:;[]().,!?*" (not including quotes).
Examples
":-P;)8(Bo[B*]8^)::);^);0;OO:O):o):)"
Returns: ":;0;OO:O)"
"Hey! How are you jill? :) :) Good day"
Returns: "Hey! How are you jill? Good day"
"Cutey ;). :-) (-: :-) (-:"
Returns: "Cutey . (-: (-:"
"There are three things: 0), 1),and 2) "
Returns: "There are three things: 0), 1),and 2) "
":) :) :) :) :) :) :) :) :) :) :) :)"
Returns: " "
":P:):(:[:]:-P:-):-(:-[:-]:oP:o):o(:o[:o]"
Returns: ""
""
Returns: ""
"I like talking! 8). -- wide open eyes."
Returns: "I like talking! . -- wide open eyes."
"!8P!8)!B(!B[!B]!B-P!B-!)!8-(!B-[!;-]!;oP!;o)!;o("
Returns: "!!!!!!!B-!)!!!!!!"
"::)):-:-))8)8P*)P8P8-P8^8^8^PPP:--):^^):^))::^)"
Returns: ":):-)*)P8^8^PP:--):^^)):"
"::)) ::-))"
Returns: ":) :)"
" !! How are you doing today, pogsworth? :) :) :-)"
Returns: " !! How are you doing today, pogsworth? "
"Hello how are you :) I am doing fine. :-)"
Returns: "Hello how are you I am doing fine. "
"(-: backwards smilies are not removed."
Returns: "(-: backwards smilies are not removed."
"(1)(2)(3)(4)(5)(6)(7)(8)(9)(10))8o)"
Returns: "(1)(2)(3)(4)(5)(6)(7)((9)(10))"
":*Ph:*(i:*)s:*[ i:^Ps: ^ (a: ^ [ :^]t8Pe8)s8(t"
Returns: "his is: ^ (a: ^ [ test"
":"
Returns: ":"
":)):-:):)"
Returns: "):-"
":::"
Returns: ":::"
"hi - t:)here"
Returns: "hi - there"
" : B--( :0 :o ;^ B- [8 :0) :: :O) B^p b^P :::-):- "
Returns: " : B--( :0 :o ;^ B- [8 :0) :: :O) B^p b^P :::- "
":]"
Returns: ""
" :-):-) "
Returns: " "
"hello:"
Returns: "hello:"
":-):*)"
Returns: ""
"::-))"
Returns: ":)"
"P"
Returns: "P"
"ENMEMMMENEMENM:)"
Returns: "ENMEMMMENEMENM"
"12345::o))67B]"
Returns: "12345:)67"
":--)"
Returns: ":--)"
":):)))) :8"
Returns: "))) :8"
":-):-)"
Returns: ""
"test:;-)^(ersr:)"
Returns: "test:^(ersr"
"::))"
Returns: ":)"
":)[:-:)[:-P):););-:)[:-P):););--);):)[:-P):););--)"
Returns: "[:-[);-[);--)[);--)"
":)"
Returns: ""
":O[:op"
Returns: ":O[:op"
"test:"
Returns: "test:"
"! !:()(::():P::*():^]::)):)::)::()::(] : : ) : ((:"
Returns: "! !)(:):):)::):] : : ) : ((:"
";:))"
Returns: ";)"
"-P:"
Returns: "-P:"
" a8B d:-)e:--):(:^^Pg:)q):*) l;^n:-m):-)ab:-"
Returns: " a8B de:--):^^Pgq) l;^n:-m)ab:-"
":-):)"
Returns: ""
"X:):)X"
Returns: "XX"
":):):))))) :8"
Returns: ")))) :8"
"::P)"
Returns: ":)"
":;-))blah"
Returns: ":)blah"
":****)"
Returns: ":****)"
"HI:-("
Returns: "HI"
":):):-) adfasdfas asdfads*P"
Returns: " adfasdfas asdfads*P"
":-:)"
Returns: ":-"
":-a"
Returns: ":-a"
"testing :o) oh yeah"
Returns: "testing oh yeah"
":):):::::)-]8oPPP]"
Returns: "::::-]PP]"
"::)[ b;:-(^(P"
Returns: ":[ b;^(P"
":********)"
Returns: ":********)"
"testme ::-"
Returns: "testme ::-"
" :- :):- :0x:* :ox(: :0) :O)x:O :q]x:-p b-P :-^)"
Returns: " :- :- :0x:* :ox(: :0) :O)x:O :q]x:-p b-P :-^)"
":-"
Returns: ":-"
"T:*Ph:*(i:*)s:*[ :*]i:^Ps:^) :^(a:^[ :^]t8Pe8)s8(t"
Returns: "This is a test"
"this is :) a test :"
Returns: "this is a test :"
"T:*Ph:*(i:*)s:*[ :*]i:^Ps:]t8Pe8)s8(t:::-):(:;"
Returns: "This istest:::;"
":):-)8P afgagjk agfgaja:::]]]"
Returns: " afgagjk agfgaja::]]"
"B"
Returns: "B"
"ha :^"
Returns: "ha :^"
":);):::::)-]8oPPP]"
Returns: "::::-]PP]"
"a"
Returns: "a"
"hi:"
Returns: "hi:"
":-hi"
Returns: ":-hi"
":*) f())) ;] i[] ::-() :-) :) : - ) :- ) ::-)::):"
Returns: " f())) i[] :) : - ) :- ) :::"
"T:*Ph::*)s(a:^[ :^]t8Pe8)s8(t ::::))))) :8*)"
Returns: "Th:s(a test :::)))) :"
":):)"
Returns: ""
"::)) ::-))"
Returns: ":) :)"
note that smilies are not removed recursively.
" !! How are you doing today, pogsworth? :) :) :-)"
Returns: " !! How are you doing today, pogsworth? "
note that the spaces are preserved
"Hello how are you :) I am doing fine. :-)"
Returns: "Hello how are you I am doing fine. "
"(-: backwards smilies are not removed."
Returns: "(-: backwards smilies are not removed."
"T:*Ph:*(i:*)s:*[ :*]i:^Ps:^) :^(a:^[ :^]t8Pe8)s8(t"
Returns: "This is a test"
""
Returns: ""