Esempio n. 1
0
        public bool CanBeConcatenatedWith(TokenBase other)
        {
            if (other == null)
            {
                return(false);
            }
            var otherEncodedWord = other as EncodedWord;

            if (otherEncodedWord == null || otherEncodedWord._charset != _charset || otherEncodedWord._encoding != _encoding)
            {
                return(false);
            }
            if (IsBase64 && _rawValue.EndsWith("="))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        private static string OutputTokens(TokenBase token)
        {
            if (token == null)
            {
                return(string.Empty);
            }

            var nextSeparatorStringValue = token.NextSeparator != null?token.NextSeparator.GetStringValue() : string.Empty;

            if (token is AsciiWord)
            {
                return(token.GetStringValue() + nextSeparatorStringValue + OutputTokens(token.NextWord));
            }

            if (token is EncodedWord)
            {
                var encodedWordToken = token as EncodedWord;
                if (encodedWordToken.CanBeConcatenatedWith(encodedWordToken.NextWord))
                {
                    return(OutputTokens(EncodedWord.Concat(encodedWordToken, encodedWordToken.NextWord as EncodedWord)));
                }

                if (encodedWordToken.NextWord is EncodedWord)
                {
                    return(token.GetStringValue() + OutputTokens(token.NextWord));
                }

                return(token.GetStringValue() + nextSeparatorStringValue + OutputTokens(token.NextWord));
            }

            if (token is Separator)
            {
                if (token.NextWord is EncodedWord)
                {
                    return(OutputTokens(token.NextWord));
                }
                return(token.GetStringValue() + OutputTokens(token.NextWord));
            }

            throw new InvalidOperationException("Unknown token type");
        }