added QuotedPrintable{De,En}coder.
This commit is contained in:
		
							parent
							
								
									01df7ac29c
								
							
						
					
					
						commit
						02735ff4a1
					
				
					 7 changed files with 72 additions and 28 deletions
				
			
		|  | @ -32,6 +32,9 @@ export class AppComponent extends OnInit { | ||||||
|             try { |             try { | ||||||
|                 result = converter.convert(content); |                 result = converter.convert(content); | ||||||
|             } catch (error) { |             } catch (error) { | ||||||
|  |                 if (typeof console === "object" && typeof console.log === "function") { | ||||||
|  |                     console.log(error); | ||||||
|  |                 } | ||||||
|                 result = null; |                 result = null; | ||||||
|             } |             } | ||||||
|             if (result === null) { |             if (result === null) { | ||||||
|  |  | ||||||
							
								
								
									
										42
									
								
								app/converter/quotedprintabledecoder.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								app/converter/quotedprintabledecoder.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,42 @@ | ||||||
|  | import {Converter} from "./converter"; | ||||||
|  | 
 | ||||||
|  | declare var window:any; | ||||||
|  | 
 | ||||||
|  | export class QuotedPrintableDecoder implements Converter { | ||||||
|  | 
 | ||||||
|  |     private utf8:any = window.utf8; | ||||||
|  |     private quotedPrintable:any = window.quotedPrintable; | ||||||
|  | 
 | ||||||
|  |     getDisplayname():string { | ||||||
|  |         return "Decode quoted printable"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     getId():string { | ||||||
|  |         return "decodequotedprintable"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     convert(input:string):string { | ||||||
|  |         return this.utf8.decode(this.quotedPrintable.decode(input)); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  { | ||||||
|  |  "id": "decodequotedprintable", | ||||||
|  |  "name": "Decode quoted printable", | ||||||
|  |  "convert": function (input) { | ||||||
|  |  try { | ||||||
|  |  return { | ||||||
|  |  "status": "OK", | ||||||
|  |  "content": utf8.decode(quotedPrintable.decode(input)) | ||||||
|  |  }; | ||||||
|  |  } catch (exception) { | ||||||
|  |  return { | ||||||
|  |  "status": "ERROR", | ||||||
|  |  "content": "Invalid quoted printable string." | ||||||
|  |  }; | ||||||
|  |  } | ||||||
|  |  } | ||||||
|  |  }, | ||||||
|  | 
 | ||||||
|  |  */ | ||||||
							
								
								
									
										18
									
								
								app/converter/quotedprintableencoder.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								app/converter/quotedprintableencoder.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,18 @@ | ||||||
|  | import {Converter} from "./converter"; | ||||||
|  | 
 | ||||||
|  | declare var window:any; | ||||||
|  | 
 | ||||||
|  | export class QuotedPrintableEncoder implements Converter { | ||||||
|  | 
 | ||||||
|  |     getDisplayname():string { | ||||||
|  |         return "Encode quoted printable"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     getId():string { | ||||||
|  |         return "encodequotedprintable"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     convert(input:string):string { | ||||||
|  |         return window.quotedPrintable.encode(window.utf8.encode(input)); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -12,6 +12,8 @@ import {DecToHexConverter} from "./converter/dectohexconverter"; | ||||||
| import {HexToDecConverter} from "./converter/hextodecconverter"; | import {HexToDecConverter} from "./converter/hextodecconverter"; | ||||||
| import {DecToBinConverter} from "./converter/dectobinconverter"; | import {DecToBinConverter} from "./converter/dectobinconverter"; | ||||||
| import {BinToDecConverter} from "./converter/bintodecconverter"; | import {BinToDecConverter} from "./converter/bintodecconverter"; | ||||||
|  | import {QuotedPrintableDecoder} from "./converter/quotedprintabledecoder"; | ||||||
|  | import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder"; | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class ConverterregistryService { | export class ConverterregistryService { | ||||||
|  | @ -47,6 +49,8 @@ export class ConverterregistryService { | ||||||
|         this.registerConverter(new HexToDecConverter()); |         this.registerConverter(new HexToDecConverter()); | ||||||
|         this.registerConverter(new DecToBinConverter()); |         this.registerConverter(new DecToBinConverter()); | ||||||
|         this.registerConverter(new BinToDecConverter()); |         this.registerConverter(new BinToDecConverter()); | ||||||
|  |         this.registerConverter(new QuotedPrintableEncoder()); | ||||||
|  |         this.registerConverter(new QuotedPrintableDecoder()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private registerConverter(converter:Converter):void { |     private registerConverter(converter:Converter):void { | ||||||
|  |  | ||||||
							
								
								
									
										27
									
								
								dencode.js
									
										
									
									
									
								
							
							
						
						
									
										27
									
								
								dencode.js
									
										
									
									
									
								
							|  | @ -9,33 +9,6 @@ | ||||||
| 					"content": "" | 					"content": "" | ||||||
| 				}; | 				}; | ||||||
| 			} | 			} | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			"id": "decodequotedprintable", |  | ||||||
| 			"name": "Decode quoted printable", |  | ||||||
| 			"convert": function (input) { |  | ||||||
| 				try { |  | ||||||
| 					return { |  | ||||||
| 						"status": "OK", |  | ||||||
| 						"content": utf8.decode(quotedPrintable.decode(input)) |  | ||||||
| 					}; |  | ||||||
| 				} catch (exception) { |  | ||||||
| 					return { |  | ||||||
| 						"status": "ERROR", |  | ||||||
| 						"content": "Invalid quoted printable string." |  | ||||||
| 					}; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			"id": "encodequotedprintable", |  | ||||||
| 			"name": "Encode quoted printable", |  | ||||||
| 			"convert": function (input) { |  | ||||||
| 				return { |  | ||||||
| 					"status": "OK", |  | ||||||
| 					"content": quotedPrintable.encode(utf8.encode(input)) |  | ||||||
| 				}; |  | ||||||
| 			} |  | ||||||
| 		} | 		} | ||||||
| 	]; | 	]; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -9,6 +9,8 @@ | ||||||
|     <script type="text/javascript" src="node_modules/zone.js/dist/zone.js"></script> |     <script type="text/javascript" src="node_modules/zone.js/dist/zone.js"></script> | ||||||
|     <script type="text/javascript" src="node_modules/reflect-metadata/Reflect.js"></script> |     <script type="text/javascript" src="node_modules/reflect-metadata/Reflect.js"></script> | ||||||
|     <script type="text/javascript" src="node_modules/systemjs/dist/system.src.js"></script> |     <script type="text/javascript" src="node_modules/systemjs/dist/system.src.js"></script> | ||||||
|  |     <script type="text/javascript" src="node_modules/utf8/utf8.js"></script> | ||||||
|  |     <script type="text/javascript" src="node_modules/quoted-printable/quoted-printable.js"></script> | ||||||
| 
 | 
 | ||||||
|     <script type="text/javascript" src="systemjs.config.js"></script> |     <script type="text/javascript" src="systemjs.config.js"></script> | ||||||
|     <script type="text/javascript"> |     <script type="text/javascript"> | ||||||
|  |  | ||||||
|  | @ -25,7 +25,9 @@ | ||||||
|     "reflect-metadata": "^0.1.3", |     "reflect-metadata": "^0.1.3", | ||||||
|     "rxjs": "5.0.0-beta.12", |     "rxjs": "5.0.0-beta.12", | ||||||
|     "systemjs": "^0.19.27", |     "systemjs": "^0.19.27", | ||||||
|     "zone.js": "^0.6.12" |     "zone.js": "^0.6.12", | ||||||
|  |     "quoted-printable": "^1.0.0", | ||||||
|  |     "utf8": "^2.1.1" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|     "concurrently": "^2.2.0", |     "concurrently": "^2.2.0", | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue