@@ -758,6 +758,9 @@ Parser.prototype.generateString = function(ctx) {
758758 if ( this . options . stripNull ) {
759759 ctx . pushCode ( "{0} = {0}.replace(/\\x00+$/g, '')" , name ) ;
760760 }
761+ if ( this . options . trim ) {
762+ ctx . pushCode ( "{0} = {0}.trim()" , name ) ;
763+ }
761764} ;
762765
763766Parser . prototype . generate_encodeString = function ( ctx ) {
@@ -780,13 +783,22 @@ Parser.prototype.generate_encodeString = function(ctx) {
780783 // Compute padding length
781784 var padLen = ctx . generateTmpVariable ( ) ;
782785 ctx . pushCode ( "{0} = {1} - {2}.length;" , padLen , optLength , tmpBuf ) ;
786+ if ( this . options . padding === "left" ) {
787+ // Add heading padding spaces
788+ ctx . pushCode (
789+ "if ({0} > 0) {smartBuffer.writeString(' '.repeat({0}));}" ,
790+ padLen
791+ ) ;
792+ }
783793 // Copy the temporary string buffer to current smartBuffer
784794 ctx . pushCode ( "smartBuffer.writeBuffer({0});" , tmpBuf ) ;
785- // Add padding spaces
786- ctx . pushCode (
787- "if ({0} > 0) {smartBuffer.writeString(' '.repeat({0}));}" ,
788- padLen
789- ) ;
795+ if ( this . options . padding !== "left" ) {
796+ // Add trailing padding spaces
797+ ctx . pushCode (
798+ "if ({0} > 0) {smartBuffer.writeString(' '.repeat({0}));}" ,
799+ padLen
800+ ) ;
801+ }
790802 } else {
791803 ctx . pushCode (
792804 "smartBuffer.writeString({0}, '{1}');" ,
0 commit comments