Русские субтитры: Добавление пробелов после выбранных символов - Русские субтитры

Перейти к содержимому

Страница 1 из 1
  • Вы не можете создать новую тему
  • Вы не можете ответить в тему

Добавление пробелов после выбранных символов

#1 Пользователь офлайн   BedaZzle Иконка

  • Иконка
  • Отправить ЛС
  • Группа: Admin
  • Сообщений: 2 991
  • Регистрация: 22 Октябрь 02
  • Страна:
  • Прислал(a) субтитров: 96
  • Своих переводов: 16

Отправлено 25 Сентябрь 2011 - 23:37

Добавление пробелов после символов ! ? ; . ,


// Add spaces after punctuation marks - ! ? ; . , 
// Made by Bedazzle, 2011.09.25

program AddSpacesAfterPunctuation;

// ---------------------------------------------
const
  CRLF = ''#13''#10;

var
  n, i : Integer;
  txt : String;

// ---------------------------------------------

function ReplaceAll(t, s, r : String): String;
var
  p : Integer;
begin
  Result := '';
  p := pos(s, t);
  while p > 0 do
  begin
    Result := Result + copy(t, 1, p-1) + r;
    t := copy(t, p+length(s), length(t)-p-length(s)+1);
    p := pos(s, t);
  end;
  Result := Result + t;
end;

// ---------------------------------------------

function TrimLines(t : String): String;
var
  p : Integer;
begin
  Result := '';
  p := pos(CRLF, t);
  while p > 0 do
  begin
    Result := Result + trim(copy(t, 1, p-1)) + CRLF;
    t := copy(t, p+length(CRLF), length(t)-p-length(CRLF)+1);
    p := pos(CRLF, t);
  end;
  Result := Result + trim(t);
end;

// ---------------------------------------------

begin
  n := GetSubtitleCount;

  for i := 0 to n-1 do
  begin
    txt := GetSubtitleText(i);

    txt := ReplaceAll(txt, '?', '? ');
    txt := ReplaceAll(txt, '!', '! ');
    txt := ReplaceAll(txt, ',', ', ');
    txt := ReplaceAll(txt, '.', '. ');
    txt := ReplaceAll(txt, ';', '; ');
    txt := ReplaceAll(txt, '. . . ', '... ');
    txt := ReplaceAll(txt, '  ', ' ');
    txt := TrimLines(txt);

    SetSubtitleText(i, txt);
  end;
end.

0

Страница 1 из 1
  • Вы не можете создать новую тему
  • Вы не можете ответить в тему