New text file line delimiter

本文介绍如何在Eclipse中设置文件的编码格式及换行符样式,包括设定新建文件的默认编码和换行符,以及如何修改现有文件的编码格式与换行符。

Window -> Preferences -> General -> Workspace :


Text file encoding :
Default : 选择此项将设定文件为系统默认的编码格式,后边会有提示具体是什么。
Other   : 选择一个具体的编码格式。


New text file line delimiter :
Default : 选择此项将设定新建的文件换行符为系统默认的换行符。
Other   : 选择一个具体的换行符样式。


换行符分别有:
Windows    : CRLF 0D0A 1310 \r\n (Carriage Return/Line Feed)
Unix/Linux : LF 0A 10 \n
Mac OS     : CR 0D 13 \r


编码格式设定将影响新建的文件和修改保存后的文件。
换行符设定只影响新建的文件,修改后保存将延续文件保存之前的换行符设定。


修改已存在文件的编码格式:
选择文件或文件夹 -> Properties -> Resource -> Text file encoding


修改已存在文件的换行符:

选择文件或文件夹 -> File -> Convert Line Delimiter To

 

转载于:https://www.cnblogs.com/fpcbk/p/9067357.html

function updateA2LAddresses() % 选择A2L文件 [a2lFile, a2lPath] = uigetfile('*.a2l', 'Select A2L File'); if isequal(a2lFile, 0), return; end a2lFullPath = fullfile(a2lPath, a2lFile); % 选择MAP文件 [mapFile, mapPath] = uigetfile('*.map', 'Select MAP File'); if isequal(mapFile, 0), return; end mapFullPath = fullfile(mapPath, mapFile); % 解析MAP文件获取符号地址 symbolMap = parseMapFile(mapFullPath); % 读取并处理A2L文件 newA2lContent = processA2LFile(a2lFullPath, symbolMap); % 保存新的A2L文件(保存在脚本所在目录) [~, name, ext] = fileparts(a2lFile); newA2lFile = [name '_updated' ext]; fid = fopen(newA2lFile, 'w'); fprintf(fid, '%s\n', newA2lContent{:}); fclose(fid); fprintf('New A2L file saved: %s\n', newA2lFile); end function symbolMap = parseMapFile(mapFile) % 初始化符号映射容器 symbolMap = containers.Map('KeyType', 'char', 'ValueType', 'char'); % 读取MAP文件内容 fid = fopen(mapFile, 'r'); mapText = textscan(fid, '%s', 'Delimiter', '\n', 'Whitespace', ''); fclose(fid); mapLines = mapText{1}; % 查找全局符号表起始位置 startIdx = find(contains(mapLines, '*** GLOBAL SYMBOLS ***'), 1); if isempty(startIdx) error('GLOBAL SYMBOLS section not found in MAP file.'); end % 解析符号表(跳过表头行) for i = (startIdx + 2):length(mapLines) line = strtrim(mapLines{i}); if isempty(line), break; end % 遇到空行结束 % 分割行内容(地址、符号名) tokens = strsplit(line); if numel(tokens) < 4, continue; end addr = tokens{1}; symbol = tokens{4}; % 验证地址格式(8位十六进制) if ~isempty(regexp(addr, '^[0-9A-Fa-f]{8}$', 'once')) symbolMap(symbol) = addr; end end end function newLines = processA2LFile(a2lFile, symbolMap) % 读取A2L文件 fid = fopen(a2lFile, 'r'); a2lText = textscan(fid, '%s', 'Delimiter', '\n', 'Whitespace', ''); fclose(fid); a2lLines = a2lText{1}; newLines = a2lLines; % 状态机变量 inCharacteristic = false; inMeasurement = false; currentSymbol = ''; % 遍历所有行 for i = 1:numel(a2lLines) line = strtrim(a2lLines{i}); % 检测块开始/结束 if contains(line, '/begin CHARACTERISTIC') inCharacteristic = true; currentSymbol = ''; elseif contains(line, '/end CHARACTERISTIC') inCharacteristic = false; elseif contains(line, '/begin MEASUREMENT') inMeasurement = true; currentSymbol = ''; elseif contains(line, '/end MEASUREMENT') inMeasurement = false; end % 提取符号名称 if (inCharacteristic || inMeasurement) && contains(line, 'Name') match = regexp(line, 'Name\s+"(.+?)"', 'tokens'); if ~isempty(match) currentSymbol = match{1}{1}; end end % 检测并替换地址 if (inCharacteristic || inMeasurement) && ... (contains(line, '/* ECU Address */') || contains(line, 'ECU_ADDRESS')) % 尝试匹配原始符号或带下划线的符号 addr = ''; if symbolMap.isKey(currentSymbol) addr = symbolMap(currentSymbol); elseif symbolMap.isKey(['_' currentSymbol]) addr = symbolMap(['_' currentSymbol]); end % 替换地址 if ~isempty(addr) newAddr = ['0x' upper(addr)]; newLine = regexprep(line, '0x[0-9A-Fa-f]+', newAddr, 'once', 'ignorecase'); newLines{i} = newLine; end end end end
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值