rejetto forum

Extension for the symbols %xxxx%

Mars · 4 · 1572

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
I had to create a variable %item-md5% to work on files MD5, but I met some concerns of replacement: nothing crossed it.

As a result, I modified the procedure handleSymbols() by adding her one or two rules more

1) It is possible to use numeric symbols  in the names as %var5max21%

2) the name must begin by an only one '_' or  by letters 'a'..'z' and 'A'..'Z'
    With the compulsory rule  that the first char  '_'  must be followed necessarily by a letter

are accepted %symbol1% , %_symbol2% , %folder%  but ar forbidden %5mars% or %_45_test%

Quote
  procedure handleSymbols();
  var
    b, e, l : integer;
    s, newS: string;
  begin
  e:=0;
  l:=length(txt);
  while e < l do
    begin
    // search for next symbol
    b:=posEx('%',txt,e+1);
    if b = 0 then break;
    e:=b+1;
    if txt[e]='_' then inc(e); //first char can be a '_' but necessary with a letter after
    if not (txt[e] in ['a'..'z','A'..'Z']) then continue; // assume that the first char is a letter
    while (e < l) and (txt[e] in ['0'..'9','a'..'z','A'..'Z','-','_']) do  //accept numeric char
      inc(e);
    if txt[e] <> '%' then continue;


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
ok, but i think it's unnecessary to allow only 1 '_' as first character.
who cares?
i changed this

    if txt[e]='_' then inc(e); //first char can be a '_' but necessary with a letter after
    if not (txt[e] in ['a'..'z','A'..'Z']) then continue; // assume that the first char is a

into this
if not (txt[e] in ['_','a'..'z','A'..'Z']) then continue; // first valid character


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2039
    • View Profile
with your change: '_---------' or '________' are valid symbols ;D
Quote
Identificateurs:

Les identificateurs désignent les constantes, variables, champs, types, propriétés, procédures, fonctions, programmes, unités, bibliothèques et packages. La longueur d'un identificateur peut être quelconque, mais seuls les 255 premiers caractères sont significatifs. Un identificateur doit commencer par un caractère alphabétique ou un souligné (_) et ne peut contenir d'espaces ; après le premier caractère, les caractères alphabétiques, les chiffres et le caractère de soulignement sont autorisés. Les mots réservés ne peuvent être utilisés comme identificateurs.
 Remarque:
 Le .NET SDK déconseille l'utilisation de caractères de soulignement au début des identificateurs, car ce symbole est réservé au système.
« Last Edit: May 17, 2009, 05:40:22 PM by mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13308
    • View Profile
but.... do we have a reason to forbid that?
i forbid numbers just because %20%20 must be left as 2 encoded url spaces, and %20% must never be considered as an HFS symbol.
consider that we must not comply with .NET, every language has its rules for identifiers.
java allows unicode characters, like Φ :)