OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

RegEx problem

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
tomtom
General User
General User


Joined: 16 Apr 2004
Posts: 6

PostPosted: Mon Aug 09, 2004 12:18 pm    Post subject: RegEx problem Reply with quote

Hello,

again me, yes. I am sorry, but I just ran into another problem.

Here's the code I am working on:

Code:
Sub Make_Paragraphs

Dim Doc as Object
Dim Finde as Object
Dim Suche as Object
Dim Cursor as Object

Doc = StarDesktop.CurrentComponent
Cursor = Doc.Text.createTextCursor()
Suche = Doc.createSearchDescriptor
Suche.searchRegularExpression (True)
Suche.searchString = "\!"
Finde = Doc.findFirst (Suche)

 Cursor.goRight (1, False)
 Doc.Text.insertControlCharacter(Cursor, _
    com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)

End Sub


I tried this on a document that starts with quotations marks (""). For some reason, the script inserts a paragraph break after the first quotation mark. Maybe my regex is not correct, but surprisingly the cursor jumps to the location where the exclamation mark is. It just does not insert a paragraph break.

If anyone wants to try, here's the text I am using:
Quote:
"Softwarepatente" in Europa: Die Gefahr besteht weiter
Demnächst werden das Europäische Parlament und der Ministerrat erneut über die Legalisierung und Einführung der sogenannten "Software-Patente" auch in Europa entscheiden, mit denen bereits in anderen Ländern große Firmen ihre Konkurrenz aus dem Markt drängen. Dies kann dazu führen, dass viele Software-Projekte wie auch KNOPPIX demnächst nicht mehr in Europa weiterentwickelt werden können, da durch bereits jetzt über 30.000 erteilte europäische "Software-Patente" (derzeit noch ohne Rechtsgrundlage) deren Inhabern Monopol- und Lizenzgebührenansprüche auf triviale Dinge wie "Fortschrittsbalken", "Mausklicks in Online-Bestellformularen", "Scrollen in Fenstern" und ähnliches entstehen. Software-Entwickler müssten also zukünftig auch für ihre eigene, vollständig selbst entwickelte Software, die eines dieser Patente möglicherweise verletzt, Lizenzgebühren an den "Software-Patentinhaber" bezahlen, was die Entwicklung neuer innovativer Software für kleine und mittelständische Unternehmen de facto unmöglich machen kann (ganz abgesehen vom Aufwand bei der Recherche und den Kosten der Rechtshilfen, um überhaupt festzustellen, welche "Software-Patente" verletzt werden könnten, wenn man die eigenen Entwicklungen weiterhin vertreiben möchte)! Im Gegensatz zu echten Patenten auf technische Erfindungen sind "Software-Patente" im von der Kommission vorgeschlagenen Richtlinenentwurf Monopolansprüche auf Geschäftsideen und Verfahren, auch ganz ohne eine konkrete technische Implementierung.


I'd appreciate any comments. I am somewhat tired today and may have made a mistake that I just can't see.

Sonja Wink
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Mon Aug 09, 2004 5:31 pm    Post subject: Reply with quote

I added some comments and changed your code. This code works.
Code:
Sub Make_Paragraphs

  Dim Doc as Object
  Dim Finde as Object
  Dim Suche as Object
  Dim Cursor as Object

  Doc = StarDesktop.CurrentComponent
  Doc = ThisComponent
  Cursor = Doc.Text.createTextCursor()
  Suche = Doc.createSearchDescriptor()
 
  REM Suche.searchRegularExpression (True)
  Suche.searchRegularExpression = True
  Suche.searchString = "\!"
  Finde = Doc.findFirst (Suche)

  REM Check the return value, it is safer! 
  If NOT IsNull(Finde) Then
 
    REM Now, move the cursor to the location!
    Cursor.gotoRange(Finde, False)
    Cursor.goRight (1, False)
    Doc.Text.insertControlCharacter(Cursor, _
      com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  End If
End Sub

Two problems. first, you never actually found anything because you never set regular expressions to True. Second, you never moved the cursor to the found text. That said, this code is not that safe because you simply assume that there is only one text object. Place your found text in a table or text section and this code will fail!
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
tomtom
General User
General User


Joined: 16 Apr 2004
Posts: 6

PostPosted: Tue Aug 10, 2004 3:28 am    Post subject: Reply with quote

Thanks Andrew.

Actually I realized what the problem was myself shortly after I had posted the question. I am aware of the limitations of this script, but then it is supposed to work on a plain text, no tables or other fancy text objects.

Again, thanks.

Kindly,

Sonja Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group