Page 1 of 1

[Solved Elsewhere] Is there any API opposite of EOF?

Posted: Mon Jul 31, 2017 2:10 pm
by rajibando
Please peruse this API on EOF.
Is there any API opposite of EOF? Like the Boolean testing of the Beginning Of File? And Going to the BOF? It is very much required! Because I want a second search from the beginning of the file after the first ends at the EOF.

Re: Is there any API opposite of EOF?

Posted: Mon Jul 31, 2017 3:25 pm
by JeJe

Re: Is there any API opposite of EOF?

Posted: Mon Jul 31, 2017 3:57 pm
by rajibando
Searched for examples, and read and found these codes here:

Code: Select all

uno::Any aRet = cppu::queryInterface( rType,
                                          (static_cast< io::XInputStream* >(this)),
                                          (static_cast< io::XSeekable* >(this)) );
The user mohitchugh never visited the forum again, so the case of PMing him or Helmar, who visited only twice, to learn doesn't arise.

How to use them here to bring the pointer/cursor to the beginning of the file before running the following function? :

Code: Select all

    REM Reiteration to remove empty paras after above action
        Function Writer_ReplaceAll_Blank_Paras() As Long
        Dim bReplace as Object
        bReplace = ThisComponent.createReplaceDescriptor()
        bReplace.setSearchString( chr(10) + "^$" )
        bReplace.setReplaceString( chr(10)  )
        bReplace.SearchRegularExpression = True
        Writer_ReplaceAll_Blank_Paras = ThisComponent.replaceAll( bReplace )
       End Function

Re: Is there any API opposite of EOF?

Posted: Mon Jul 31, 2017 5:10 pm
by FJCC
Input streams are not related to the find and replace functions in macros. The replaceAll() function will, as I understand it, search the entire document without any need to tell it where to start. I do see a problem with your SearchString. I don't see how chr(10) + "^$" can find anything. It represents a linefeed followed by an empty paragraph but a linefeed does not end a paragraph, so what is between the linefeed and the empty paragraph? Do you want to search for a linefeed at the end of a paragraph? That would be "\n$".

Re: Is there any API opposite of EOF?

Posted: Mon Jul 31, 2017 6:13 pm
by rajibando
FJCC wrote: The replaceAll() function will ... search the entire document without any need to tell it where to start
Okay, that is great! So I will not have to work on that code that much! Thanks!
I just wanted to incorporate that pattern, I did not want to involve you as Zizi is handling that post.
The post is here: A Specific Macro with Find-Replace?
...
FJCC wrote:... I don't see how chr(10) + "^$" can find anything...
Okay, please look at the attached file:
WhatIwant.odt
What I need is to remove the empty ¶ mark just after the ↲
(11.31 KiB) Downloaded 274 times
, you shalll see the need for that particular string "↲¶", where ¶ is the empty paragraph "^$" in my text to be removed.

Re: Is there any API opposite of EOF?

Posted: Mon Jul 31, 2017 9:11 pm
by FJCC
Perhaps we are using different terminology but I don't see any empty paragraphs in your document. When I view it with non-printing characters visible, I see a mixture of line feeds (↲) and paragraph marks (¶) and in no case does a line feed come immediately before a paragraph mark.
ParaMarks.JPG
Do you want to replace all ¶ with ↲? That will convert your document to a single paragraph, which can cause problems because there is a limit to size of a paragraph. Searching for "$" and replacing with CHR(10) will do that.

Re: Is there any API opposite of EOF?

Posted: Tue Aug 01, 2017 3:58 am
by rajibando
That one was the perfect file, manually edited.
The two are the initial 'Test' file, and the result of the macro application to output 'Tested' file.
You didn't look at the indicated thread, which Zizi is handling?
This macro is as follows:

Code: Select all

rem *****************************************
Function Writer_ReplaceAll_Paragraph_Breaks_With_Linefeeds() As Long
REM Replaces all Paragraph breaks with a Linefeed character within the current Writer document.
REM Returns: the number of found/replaced occurrences.
    Dim oReplace as Object
    oReplace = ThisComponent.createReplaceDescriptor()
    oReplace.setSearchString( "[a-z,A-Z,0-9]$" )
    oReplace.setReplaceString( "&" + chr(10) )
    oReplace.SearchRegularExpression = True
    Writer_ReplaceAll_Paragraph_Breaks_With_Linefeeds = ThisComponent.replaceAll( oReplace )
    End Function
Change from 'this' to 'this', from file 'tested.odt' to 'whatIwant.odt'
Change from 'this' to 'this', from file 'tested.odt' to 'whatIwant.odt'
test.odt
The initial file where ¶ are to be replaced by ↲
(11.27 KiB) Downloaded 301 times
tested.odt
The file after the present macro is run, replacing ¶ with ¶ ↲
(11.3 KiB) Downloaded 289 times
and after application of the macro