Menu

#29 Convert \n to 


1.0
open
nobody
None
2022-05-09
2022-04-15
No

When writing an XML file the method quote_attrib(inStr) in the corresponding super class should also consider replacing \n with 
.

Discussion

  • Dave Kuhlman

    Dave Kuhlman - 2022-04-18

    Gabriel,

    Thanks for the note.

    Your suggestion to transformed "\n" to " " sounds good to me.
    Although, I actually have no idea what the correct policy should be
    on this. If you have a rational, I'd be interested.

    I added a line to generateDS.py that replaces "\n" with " ".
    Hope I got it right.

    Attached is a patch.

    Please let me know whether this is what you intended and whether it
    works for you. If it works, I'll create a new release.

    Thanks for help.

    Dave

     
  • Dave Kuhlman

    Dave Kuhlman - 2022-05-03

    Gabriel,

    I've created a new release: v. 2.40.11. It has been uploaded to sourceforge.net and to pypi.org.

    Thanks for your help with this.

    Dave

     
  • Gabriel Kleinoscheg

    Dave,

    thank you for the quick response and implementation.

    I still owe you some explanation about this - the best I found is here https://stackoverflow.com/questions/514635/represent-space-and-tab-in-xml-tag

    I hope that helps.

    Thank you!

    Gabriel

     
  • Gabriel Kleinoscheg

    Dave,

    I just got aware of the fact that you added the following line:
    s1 = s1.replace(r'\\n', '
')

    What would be the difference to the following line:
    s1 = s1.replace('\n', '
')

    Taking the test here - only s2 contains the correct output (with 
):

    string = '''asdf\nasdf'''
    s1 = string.replace(r'\\n', '
')
    print(s1)
    s2 = string.replace('\n', '
')
    print(s2)
    

    Regards,
    Gabriel

     
  • Dave Kuhlman

    Dave Kuhlman - 2022-05-04

    Concerning your question about what is the difference between the following two lines?

    s1 = s1.replace(r'\\n', '
')
    s1 = s1.replace('\n', '
')
    

    Try running the following:

    a = r'\\n'
    b = '\n'
    print(len(a))                                                      
    print(len(b))
    print(a[0])
    print(a[1])
    print(a[2])
    print(ord(b))
    

    Thanks for the link to the StackOverflow page. Yes, that is informative and is a good explanation.

    So, did that latest version (v. 2.40.11) fix things for you?

    Dave

     
  • Gabriel Kleinoscheg

    Unfortunately, no.

    However, I do have a question:
    In the source of generateDS.py I find s1 = s1.replace(r'\\n', '
'). In any other source file of your project, however, I find s1 = s1.replace(r'\n', '
'). Why this difference?
    When I run generateDS on my schema the resulting Super.py contains s1 = s1.replace(r'\n', '
')

    Here's what I found out:
    - s1 = s1.replace(r'\n', '
') would work for a string like the following s1 = 'test\\ntest'
    - s1 = s1.replace(r'\n', '
') would NOT work for a string like the following (containing a real line break) s1 = 'test\ntest'. Here s1 = s1.replace('\n', '
') would work. This would cover my use case.

    Thank you.

    Gabriel

     

    Last edit: Gabriel Kleinoscheg 2022-05-05
  • Dave Kuhlman

    Dave Kuhlman - 2022-05-05

    OK. So, attached is another patch.

    With this patch, generateDS.py produces the following line in the generated module:

    s1 = s1.replace('\n', '
')
    

    I'm actually unsure about what it is supposed to do. So, I'll wait for you to tell me that it works and solves your problem before I upload another release.

    Thanks for your very helpful and explicit description of a solution. Hope I got it right this time.

    Dave

     
  • Gabriel Kleinoscheg

    Hey,

    yes, that looks good.

    Thank you for your effort!

    Regard,
    Gabriel

     
  • Dave Kuhlman

    Dave Kuhlman - 2022-05-09

    Great,

    That patch has now been uploaded as v. 2.40.12.

    Thanks again.

    Dave

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.