<commit_before>import {EventEmitter} from 'events';
import * as path from 'path';

const DefaultSearchWindowHtml = `file://${path.join(__dirname, 'search-window.html')}`;
const ShouldDebug = !!process.env.ELECTRON_IN_PAGE_SEARCH_DEBUG;
const log = ShouldDebug ? console.log.bind(console) : function nop() { /* nop */ };

export interface InPageSearchOptions {
    searchWindowWebview?: Electron.WebViewElement;
    customCssPath?: string;
    customSearchWindowHtmlPath?: string;
    openDevToolsOfSearchWindow?: boolean;
}

type RequestId = number;
type FindInPage = (text: string, options?: Electron.FindInPageOptions) => RequestId;
type StopFindInPage = (action: Electron.StopFindInPageAtion) => void;

export type SearchTarget = Electron.WebContents | Electron.WebViewElement;

function isWebView(target: any): target is Electron.WebViewElement {
    return target.tagName !== undefined && target.tagName === 'WEBVIEW';
}

function fixPathSlashes(p: string) {
    if (path.sep === '/') {
        return p;
    }
    // Note:
    // On Windows, path separator is not '/' but browser seems to understand
    // '/' separator only. So we need to convert separator manually.
    //
    // e.g.
    //  C:\Users\foo\bar\piyo.html -> /C:/Users/foo/bar/piyo.html
    //
    // c.f.
    //  https://github.com/electron/electron/issues/1298
    const r = new RegExp(path.sep, 'g');
    let replaced = p.replace(r, '/');
    if (replaced[0] !== '/') {
        replaced = '/' + replaced;
    }
    return replaced;<commit_msg>fix replacing slashes on Windows<commit_after>import {EventEmitter} from 'events';
import * as path from 'path';

const DefaultSearchWindowHtml = `file://${path.join(__dirname, 'search-window.html')}`;
const ShouldDebug = !!process.env.ELECTRON_IN_PAGE_SEARCH_DEBUG;
const log = ShouldDebug ? console.log.bind(console) : function nop() { /* nop */ };

export interface InPageSearchOptions {
    searchWindowWebview?: Electron.WebViewElement;
    customCssPath?: string;
    customSearchWindowHtmlPath?: string;
    openDevToolsOfSearchWindow?: boolean;
}

type RequestId = number;
type FindInPage = (text: string, options?: Electron.FindInPageOptions) => RequestId;
type StopFindInPage = (action: Electron.StopFindInPageAtion) => void;

export type SearchTarget = Electron.WebContents | Electron.WebViewElement;

function isWebView(target: any): target is Electron.WebViewElement {
    return target.tagName !== undefined && target.tagName === 'WEBVIEW';
}

function fixPathSlashes(p: string) {
    if (process.platform !== 'win32') {
        return p;
    }
    // Note:
    // On Windows, path separator is not '/' but browser seems to understand
    // '/' separator only. So we need to convert separator manually.
    //
    // e.g.
    //  C:\Users\foo\bar\piyo.html -> /C:/Users/foo/bar/piyo.html
    //
    // c.f.
    //  https://github.com/electron/electron/issues/1298
    let replaced = p.replace(/\\/g, '/');
    if (replaced[0] !== '/') {
        replaced = '/' + replaced;
    }
    return replaced;
{'fraction_non_alphanumeric': 0.14346965699208444, 'fraction_numerical': 0.00395778364116095, 'mean_word_length': 3.4668630338733433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1143324', 'n_tokens_mistral': 959, 'n_tokens_neox': 932, 'n_words': 223}