Hello!
I've recently tried to dig into UTF-8 format (thanks to this thread, was a great read) and everything seems to work fine, except using RegEx.
I'm using a script when saving documents that determines wheter it is a script document of mine, including a particular header string stating the time the file was created and edited last.
The script works fine on ASCII/ANSI documents, however this regex search fails on UTF-8 documents and i fail to see why.
The header part looks like this:
This header (and some possible variations) is added using templates.
Now when i save a document, the following script is executed.
Both lines
fail to work on UTF-8 documents.
I assume it might have to do with the way digits are handled in UTF files? Yet so far i fail to figure out what's wrong here...
Any help is greatly appreciated. Thanks in advance!
I've recently tried to dig into UTF-8 format (thanks to this thread, was a great read) and everything seems to work fine, except using RegEx.
I'm using a script when saving documents that determines wheter it is a script document of mine, including a particular header string stating the time the file was created and edited last.
The script works fine on ASCII/ANSI documents, however this regex search fails on UTF-8 documents and i fail to see why.
The header part looks like this:
Code: Select all
// File written by Jochen "Khuri" Höhmann <mailadress>
// Copyright 2009
//
// File : test.php
// Begin : 2009.11.22 13:45:32
// Last Update : 2009.11.22 13:47:54
Now when i save a document, the following script is executed.
Code: Select all
var cline = UltraEdit.activeDocument.currentLineNum;
var crow = UltraEdit.activeDocument.currentColumnNum;
if (typeof(UltraEdit.activeDocumentIdx) == "undefined") crow++;
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.mode = 0;
var is_privdoc = UltraEdit.activeDocument.findReplace.find("File written by Jochen \"Khuri\" Höhmann <mailadress>");
if(is_privdoc == true) {
var time = new Date();
var currdate = time.getFullYear()+'.'+(((time.getMonth() +1).toString().length > 1) ? (time.getMonth() +1) : '0'+(time.getMonth() +1))+'.'+((time.getDate().toString().length > 1) ? time.getDate() : '0'+time.getDate())+' '+((time.getHours().toString().length > 1) ? time.getHours() : '0'+time.getHours())+':'+((time.getMinutes().toString().length > 1) ? time.getMinutes() : '0'+time.getMinutes())+':'+((time.getSeconds().toString().length > 1) ? time.getSeconds() : '0'+time.getSeconds());
UltraEdit.perlReOn();
UltraEdit.activeDocument.findReplace.regExp = true;
if(UltraEdit.activeDocument.findReplace.find("// Copyright "+time.getFullYear()) == false) {
UltraEdit.activeDocument.findReplace.replace("\\/\\/ Copyright (?:\\d{4})","// Copyright "+time.getFullYear());
}
if(UltraEdit.activeDocument.findReplace.replace("\\/\\/ Last Update : [\n\r]","// Last Update : "+currdate+"\n") == false) {
UltraEdit.activeDocument.findReplace.replace("\\/\\/ Last Update : (?:\\d{4}\\.\\d{2}\\.\\d{2} \\d{2}:\\d{2}:\\d{2})","// Last Update : "+currdate);
}
}
UltraEdit.activeDocument.gotoLine(cline,crow);
UltraEdit.save();
Code: Select all
UltraEdit.activeDocument.findReplace.replace("\\/\\/ Copyright (?:\\d{4})","// Copyright "+time.getFullYear());
and
UltraEdit.activeDocument.findReplace.replace("\\/\\/ Last Update : (?:\\d{4}\\.\\d{2}\\.\\d{2} \\d{2}:\\d{2}:\\d{2})","// Last Update : "+currdate);
I assume it might have to do with the way digits are handled in UTF files? Yet so far i fail to figure out what's wrong here...
Any help is greatly appreciated. Thanks in advance!