Author Topic: CchHtmlBreakLinesW  (Read 2423 times)

guga

  • Moderator
  • Member
  • *****
  • Posts: 1377
  • Assembly is a state of art.
    • RosAsm
CchHtmlBreakLinesW
« on: April 22, 2013, 03:33:19 AM »
Code: [Select]
;;
    CchHtmlBreakLinesW

    This function replaces paragrah marks, carriage returns and line breaks on a text with the html tag "<br>"

    Arguments:
        InputString:    The inputed unicode string in html format
        OutputString:   The outputed unicode string where the paragraphs, line feeds and carriage returns are replaced.
                        If outputstring is &NULL, the funtion will compute the necessary size of the buffer.
        StrLength:      The Size of the inputed string (in bytes) to be copied.
                        If StrLength is &NULL, the funtion will compute the necessary size of the buffer.

    Return Values:
                        If the function suceeds it will return the total amount of bytes copied to the buffer or the necessary bytes to be copied
                        If the function fails, it will return Zero. it will only fail if InputString is zeroed.

    Remarks:
                        This function have the same functionality as the one inside HtmlLite.dll from VisualStudio

    Examples of usage:

[DBL_QUOTE 022]
[OutputBuff: B$ 0 #2000]

[TesteEscape: U$ "<body>
     <%
   request.setAttribute(", DBL_QUOTE, "specialCharString", DBL_QUOTE, ", ", DBL_QUOTE, "<i> is called italic tag", DBL_QUOTE, ");
    %>
 
    HTML: ${specialCharString}
</body>
", 0]

    call StrnLenW TesteEscape
    call CchHtmlBreakLinesW TesteEscape, OutputBuff, eax
    call CchHtmlBreakLinesW TesteEscape, 0, eax
    call CchHtmlBreakLinesW TesteEscape, 0, 0
    call CchHtmlBreakLinesW TesteEscape, OutputBuff, 0
    call CchHtmlBreakLinesW TesteEscape, OutputBuff, 4


    Author:
        Beyond2000!
        apr/2.013
;;


Proc CchHtmlBreakLinesW::
    Arguments @InputString, @OutputString, @StrLength
    Local @IsZeroStr, @IsCarriage
    Uses ecx, esi, edi

    mov edi D@OutputString
    xor eax eax
    mov esi D@InputString
    On esi = 0, ExitP

    .If edi <> 0
        mov D@IsZeroStr &FALSE
        If D@StrLength = 0
            mov D@IsZeroStr &TRUE
        End_If
        mov W$edi 0
    .Else
        ; There output is ZERO. We will only analyse the len of the string
        mov D@IsZeroStr &TRUE
        mov edi esi
    .End_If

    dec D@StrLength
    mov D@IsCarriage &FALSE

    ; If input is zero null unicode string we retunr the total amount of bytes copied to it and retunr
    mov eax 1
    On W$esi = 0, ExitP
    xor eax eax ; eax is the current position that is being count

    .Do
        ..If W$esi = 0D
            mov D@IsCarriage &TRUE
            add esi 2
        ..Else_If_Or D@IsCarriage = &FALSE, W$esi <> 0A
            .If D@IsZeroStr = &FALSE
                If eax >= D@StrLength
                    mov W$edi 0 | inc eax | ExitP
                End_If
                move W$edi W$esi
            .End_If
            add edi 2
            inc eax
            add esi 2
            mov D@IsCarriage &FALSE
        ..Else
            .If D@IsZeroStr = &FALSE
                mov ecx D@StrLength | sub ecx eax
                If_Or ecx < 4, eax >= D@StrLength
                    mov W$edi 0 | inc eax | ExitP
                Else
                    mov W$edi '<' | mov W$edi+2 'b' | mov W$edi+4 'r' | mov W$edi+6 '>'
                End_If
            .End_If
            add eax 4 ; add 4 bytes of '<br>'
            add edi (4*2) ; unicode size of <br> tag
            If W$esi = 0A
                add esi 2
            End_If
            mov D@IsCarriage &FALSE
        ..End_If
    .Loop_Until W$esi = 0

    inc eax

EndP
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com