www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Concatenate strings at compile-time

reply Jonathan M. Wilbur <jonathan wilbur.space> writes:
I have a method that cannot be  nogc only because it concatenates 
strings for a long exception message, as seen below.

             throw new ASN1ValuePaddingException
             (
                 "This exception was thrown because you attempted 
to decode " ~
                 "an INTEGER that was encoded on more than the 
minimum " ~
                 "necessary bytes. " ~
                 notWhatYouMeantText ~ forMoreInformationText ~
                 debugInformationText ~ reportBugsText
             );

Those variables you see are immutable. Is there a way that I can 
combine these strings together at compile time, rather than 
having a really long string that exceeds the 120 hard line-length 
limit?
May 02 2018
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
On 03/05/2018 12:38 AM, Jonathan M. Wilbur wrote:
 I have a method that cannot be  nogc only because it concatenates 
 strings for a long exception message, as seen below.
 
              throw new ASN1ValuePaddingException
              (
                  "This exception was thrown because you
attempted to 
 decode " ~
                  "an INTEGER that was encoded on more than the
minimum " ~
                  "necessary bytes. " ~
                  notWhatYouMeantText ~ forMoreInformationText ~
                  debugInformationText ~ reportBugsText
              );
 
 Those variables you see are immutable. Is there a way that I can combine 
 these strings together at compile time, rather than having a really long 
 string that exceeds the 120 hard line-length limit?
All strings are immutable. But can they be enum?
May 02 2018
prev sibling parent Stefan Koch <uplink.coder googlemail.com> writes:
On Wednesday, 2 May 2018 at 12:38:25 UTC, Jonathan M. Wilbur 
wrote:
 I have a method that cannot be  nogc only because it 
 concatenates strings for a long exception message, as seen 
 below.

             throw new ASN1ValuePaddingException
             (
                 "This exception was thrown because you 
 attempted to decode " ~
                 "an INTEGER that was encoded on more than the 
 minimum " ~
                 "necessary bytes. " ~
                 notWhatYouMeantText ~ forMoreInformationText ~
                 debugInformationText ~ reportBugsText
             );

 Those variables you see are immutable. Is there a way that I 
 can combine these strings together at compile time, rather than 
 having a really long string that exceeds the 120 hard 
 line-length limit?
This will be concatenated at compiletime and there will be no runtime overhead iff those are static immutable or enum.
May 02 2018