www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcmultiview/@Action/pUniqueMnemonic.m
function str = pUniqueMnemonic(obj, str, PreStr) %PUNIQUEMNEMONIC Ensure that the mnemonic in a string is unique % % STR = PUNIQUEMNEMONIC(OBJ, STR, PRESTR) ensures that the mnemonic % character in the string STR is unique to those in the strings in the % cell array PRESTR. % Copyright 2005 The MathWorks, Inc. and Ford Global Technologies, Inc. MnemonicIdx = strfind(str, '&'); if ~isempty(MnemonicIdx) MnemonicIdx = MnemonicIdx(1); MnemonicChar = str(MnemonicIdx+1); PreChars = cell(size(PreStr)); PreIdx = strfind(PreStr, '&'); for n = 1:length(PreIdx) if ~isempty(PreIdx{n}) PreChars{n} = PreStr{n}(PreIdx{n}+1); else PreChars{n} = ''; end end if any(strcmpi(MnemonicChar, PreChars)) % Remove current mnemonic str(MnemonicIdx) = []; % Split into words and look for new mnemonic places Wstart = regexp(str, '\<\w'); Wend = regexp(str, '\w\>'); Wlength = Wend-Wstart+1; LetterOffset = 0; NewMnemonicIdx = 0; while any(LetterOffset<Wlength) && NewMnemonicIdx==0 for n = 1:length(Wstart) Idx = Wstart(n)+LetterOffset; if LetterOffset<Wlength(n) && ~any(strcmpi(str(Idx), PreChars)) NewMnemonicIdx = Idx; break end end LetterOffset = LetterOffset+1; end if NewMnemonicIdx>0 str = [str(1:NewMnemonicIdx-1), '&', str(NewMnemonicIdx:end)]; end end end