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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

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

Post 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.
Last edited by rajibando on Mon Aug 28, 2017 4:56 am, edited 2 times in total.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Is there any API opposite of EOF?

Post by JeJe »

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Is there any API opposite of EOF?

Post 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
Last edited by rajibando on Mon Jul 31, 2017 6:32 pm, edited 1 time in total.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Is there any API opposite of EOF?

Post 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$".
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Is there any API opposite of EOF?

Post 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 272 times
, you shalll see the need for that particular string "↲¶", where ¶ is the empty paragraph "^$" in my text to be removed.
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Is there any API opposite of EOF?

Post 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.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
rajibando
Posts: 52
Joined: Sat Jul 29, 2017 4:59 am

Re: Is there any API opposite of EOF?

Post 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 297 times
tested.odt
The file after the present macro is run, replacing ¶ with ¶ ↲
(11.3 KiB) Downloaded 282 times
and after application of the macro
LibreOffice 4.0.3.3 (Build ID: 400m0(Build:3)) in Knoppix 7.2.0
Post Reply