cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Question about OIDs and selected content...

JasonBuss
1-Newbie

Question about OIDs and selected content...

Just wondering if anyone else has tried this,

Is there a method in ACL for getting the OIDs within a selection (i.e.
to get the oids from a selection highlighted by the author?)

Working on some legacy conversion trying to convert SGML singletons that
were included into every element declaration into corresponding
attribute values for all valid elements in between the singletons. I am
beginning to think there is no good automated solution...

-Jason
2 REPLIES 2

Never Mind. I just found the selection_start/end funcs.



Thanks,



-Jason


Hi Jason,

Sounds like you don't need it, but I think this should work (this was similar to a previous question I've asked). get_selection_oids() should return an array of all the oids in the selection. The first while loop bothers me, but so far so good:

function get_selection_oids($oids[]) {

if (!selected()) { return 0; }

local $o1 = selection_start($p1);
local $o2 = selection_end($p2);
local $cur_oid = oid_forward($o1);
$cur_oid = oid_forward($o1);

while (!oid_in_selection($cur_oid)) {
$cur_oid = oid_forward($cur_oid);
}

while (oid_in_selection($cur_oid)) {
$oids[high_bound($oids) + 1] = $cur_oid;
$cur_oid = oid_forward($cur_oid);
}

}

function oid_in_selection(oid) {

if (!selected()) { return 0; }

$o1 = selection_start($p1);
$o2 = selection_end($p2);

$offset_from_start = oid_offset($o1, $p1, $oid, 0);
$offset_from_end = oid_offset($o2, $p2, $oid, 0);

return ($offset_from_start >= 0 && $offset_from_end <= 0);
}

-James


Announcements

Top Tags