## Copyright (C) 2026 Dmitri A. Sergatskov <dasergatskov@gmail.com>
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## __UNO_address_blocks__ - extract cell address blocks from UNO range strings

function adrblks = __UNO_address_blocks__ (addrs)

  adrblks = {};
  if (isempty (addrs))
    return
  endif

  blocks = regexp (char (addrs), "[,;]", "split");
  for ii = 1:numel (blocks)
    block = strtrim (blocks{ii});
    dot = find (block == ".", 1, "last");
    if (! isempty (dot))
      block = block(dot+1:end);
    endif
    block = strrep (block, "$", "");
    tok = regexp (block, ...
                  "^([A-Za-z]+[0-9]+:[A-Za-z]+[0-9]+|[A-Za-z]+[0-9]+)$", ...
                  "tokens", "once");
    if (! isempty (tok))
      adrblks{end+1} = upper (tok{1});
    endif
  endfor

endfunction
