1
1
import logging
2
2
import os
3
+ import re
3
4
from xml .etree import ElementTree
4
5
from xml .etree .ElementTree import Element as Element
5
6
@@ -443,9 +444,22 @@ def operators_total(self) -> int:
443
444
444
445
@property
445
446
def operator_num (self ) -> int :
447
+ stem = "operator" + ("-" * self ._name .count ("-" ))
446
448
total = 0
447
449
for child in self .parent .children :
448
- if child .is_function and child .name .replace (" " , "" ) in OVERLOAD_OPERATORS :
450
+ child_refid = child .name .replace (" " , "" )
451
+ # Check if the child is a displayed operator by ensuring:
452
+ # 1. Its identifier is in the predefined OVERLOAD_OPERATORS list.
453
+ # 2. It starts with the expected 'stem' derived from the parent's naming.
454
+ # 3. It does not start with an extra hyphen (stem+'-') to avoid excessive matching.
455
+ # 4. It is not private.
456
+ if (
457
+ child .is_function
458
+ and child_refid in OVERLOAD_OPERATORS
459
+ and child_refid .startswith (stem )
460
+ and not child_refid .startswith (stem + "-" )
461
+ and child ._visibility != Visibility .PRIVATE
462
+ ):
449
463
total += 1
450
464
if child .refid == self ._refid :
451
465
break
@@ -454,14 +468,19 @@ def operator_num(self) -> int:
454
468
@property
455
469
def name_url_safe (self ) -> str :
456
470
name = self .name_tokens [- 1 ]
457
- return name .replace (" " , "-" ).replace ("=" , "" ).replace ("~" , "" ).lower ()
471
+ # Strip special characters that do not appear in anchors
472
+ name = re .sub ("[=~.,<>]" , "" , name )
473
+ return name .strip (" " ).replace (" " , "-" ).lower ()
458
474
459
475
@property
460
476
def anchor (self ) -> str :
461
477
name = ""
462
478
if self ._name .replace (" " , "" ) in OVERLOAD_OPERATORS :
463
479
num = self .operator_num
464
- name = f"operator_{ str (self .operator_num - 1 )} " if num > 1 else "operator"
480
+ if self ._name .startswith ("operator-" ):
481
+ name = f"operator-_{ str (num - 1 )} " if num > 1 else "operator-"
482
+ else :
483
+ name = f"operator_{ str (num - 1 )} " if num > 1 else "operator"
465
484
elif self .is_overloaded :
466
485
name = f"{ self .name_url_safe } -{ str (self .overload_num )} { str (self .overload_total )} "
467
486
else :
0 commit comments