import { CommentSyntax } from "../Entity/Config/Contributes/Configuration" ; export class StringUtil { public static IsNullOrWhiteSpace ( line ) { return ( line === null || line . trim ( ) === '' ) ; } public static IsCodeBlockStart ( line ) { if ( line === null ) return false ; const isAttribute = line . trim ( ) . startsWith ( '[' ) ; if ( isAttribute ) return false ; const isCodeBlockStart = ( line . indexOf ( '{' ) !== - 1 ) ; if ( isCodeBlockStart ) return true ; const isInterface = ( line . indexOf ( ';' ) !== - 1 ) ; if ( isInterface ) return true ; const isEndMethod = ( line . trim ( ) . endsWith ( ')' ) ) ; if ( isEndMethod ) return true ; const isXml = ( line . indexOf ( '</' ) !== - 1 ) ; if ( isXml ) return true ; return isCodeBlockStart ; } public static RemoveComment ( line ) { if ( line === null ) return null ; return line . replace ( /\/\/.*/ , '' ) . replace ( /\/\*.*\*\// , '' ) ; } public static GetIndent ( line , indentBaseLine , insertSpaces , detectIdentation ) { if ( line === null ) return null ; const indent = indentBaseLine . match ( /([ \t]*)?/ ) [ 0 ] ; const spaces = ' ' . repeat ( indent . length ) ; if ( detectIdentation ) { const isSpaceIdentation = ( indent . match ( /([ ]+)/ ) !== null ) ; insertSpaces = isSpaceIdentation ; } if ( insertSpaces ) { return indent . split ( '\t' ) . join ( spaces ) ; } else { return indent . split ( spaces ) . join ( '\t' ) ; } } public static GetIndentLen ( indent , commentSyntax , insertSpaces , detectIdentation ) { if ( indent === null ) return 0 ; if ( detectIdentation ) { const isSpaceIdentation = ( indent . match ( /([ ]+)/ ) !== null ) ; insertSpaces = isSpaceIdentation ; } if ( insertSpaces ) { return indent . split ( ' ' ) . length ; } else { const offset = commentSyntax == CommentSyntax . delimited ? 1 : 0 ; return indent . split ( '\t' ) . length + offset ; } } }