Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/bcgsc/ntCard
06 April 2024, 01:58:22 UTC
  • Code
  • Branches (12)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/azure-macOS
    • refs/heads/low_kmer_sample_check
    • refs/heads/master
    • refs/heads/refactor
    • refs/heads/spacedseeds
    • refs/tags/1.0.0
    • refs/tags/1.0.1
    • refs/tags/1.2.0
    • refs/tags/1.2.1
    • refs/tags/1.2.2
    • refs/tags/v1.1.0
    • refs/tags/v1.1.1
    No releases to show
  • 75d2835
  • /
  • Common
  • /
  • StringUtil.h
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:395fb0258071b4915dbf86774b126f346a6e4c9b
origin badgedirectory badge Iframe embedding
swh:1:dir:944d1666550734b66e20e560551c63ecc7d4f5c9
origin badgerevision badge
swh:1:rev:741c9417282570a71c4042f0d2022493f26c4e49
origin badgesnapshot badge
swh:1:snp:9765a9dc233d6d78dbee568f9c2afba0f84bcc2b
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 741c9417282570a71c4042f0d2022493f26c4e49 authored by Johnathan Wong on 27 January 2020, 22:56:49 UTC
release 1.2.1 (#40)
Tip revision: 741c941
StringUtil.h
#ifndef STRINGUTIL_H
#define STRINGUTIL_H 1

#include <cassert>
#include <iomanip>
#include <sstream>
#include <string>
#include <cmath>

/** Return the last character of s and remove it. */
static inline char chop(std::string& s)
{
    assert(s.length() > 1);
    unsigned back = s.length() - 1;
    char c = s[back];
    s.erase(back);
    return c;
}

/** If the last character of s is c, remove it and return true. */
static inline bool chomp(std::string& s, char c = '\n')
{
    unsigned back = s.length() - 1;
    if (!s.empty() && s[back] == c) {
        s.erase(back);
        return true;
    } else
        return false;
}

/** Return the SI representation of n. */
static inline std::string toSI(double n)
{
    std::ostringstream s;
    s << std::setprecision(3);
    if (n < 1e3)
        s << n << ' ';
    else if (n < 1e6)
        s << n/1e3 << " k";
    else if (n < 1e9)
        s << n/1e6 << " M";
    else if (n < 1e12)
        s << n/1e9 << " G";
    else
        s << n/1e12 << " T";
    return s.str();
}

/** Return the SI representation of a number in bytes. */
static inline std::string bytesToSI(size_t n)
{
    std::ostringstream s;
    s << std::setprecision(3);
    if (n < 1024)
        s << n;
    else if (n < (1ULL<<20))
        s << (double)n/(1ULL<<10) << "k";
    else if (n < (1ULL<<30))
        s << (double)n/(1ULL<<20) << "M";
    else
        s << (double)n/(1ULL<<30) << "G";
    return s.str();
}

/**
 * Convert a quantity with SI units to the equivalent floating
 * point number.
 */
static inline double fromSI(std::istringstream& iss)
{
    double size;
    std::string units;

    iss >> size;
    if (iss.fail()) {
        // not prefixed by a number
        return 0;
    }

    iss >> units;
    if (iss.fail() && iss.eof()) {
        // no units given; clear fail flag
        // and just return the number
        iss.clear(std::ios::eofbit);
        return size;
    }

    if (units.size() > 1) {
        // unrecognized multichar suffix
        iss.setstate(std::ios::failbit);
        return 0;
    }

    switch(tolower(units[0])) {
    case 'k':
        size *= 1000ULL;
        break;
    case 'm':
        size *= 1000ULL*1000;
        break;
    case 'g':
        size *= 1000ULL*1000*1000;
        break;
    case 't':
        size *= 1000ULL*1000*1000*1000;
        break;
    default:
        iss.setstate(std::ios::failbit);
        return 0;
    }

    return size;
}

/**
 * Convert a quantity with SI units to the equivalent floating
 * point number.
 */
static inline double fromSI(const std::string& str)
{
    std::istringstream iss(str);
    return fromSI(iss);
}

/** Return the engineering string representation of n. */
template <typename T>
static inline std::string toEng(T n)
{
    std::ostringstream s;
    s << std::setprecision(4);
    if (n < 10000000)
        s << n;
    else if (n < 1e9)
        s << n/1e6 << "e6";
    else if (n < 1e12)
        s << n/1e9 << "e9";
    else
        s << n/1e12 << "e12";
    return s.str();
}

/** Return true if the second string is a prefix of the string s. */
template <size_t N>
bool startsWith(const std::string& s, const char (&prefix)[N])
{
    size_t n = N - 1;
    return s.size() > n && equal(s.begin(), s.begin() + n, prefix);
}

/** Return true if the second string is a suffix of the string s. */
template <size_t N>
bool endsWith(const std::string& s, const char (&suffix)[N])
{
    size_t n = N - 1;
    return s.size() > n && equal(s.end() - n, s.end(), suffix);
}

/** Return true if the second string is a suffix of the string s. */
static inline
bool endsWith(const std::string& s, const std::string& suffix)
{
    size_t n = suffix.size();
    return s.size() > n && equal(s.end() - n, s.end(),
                                 suffix.begin());
}

static inline
bool isReadNamePair(const std::string& name1, const std::string& name2)
{
    assert(!name1.empty() && !name2.empty());

    if (name1 == name2)
        return true;

    if (endsWith(name1,"/1") && endsWith(name2,"/2")) {
        int len1 = name1.length();
        int len2 = name2.length();
        assert(len1 > 2 && len2 > 2);
        return name1.compare(0, len1-2, name2, 0, len2-2) == 0;
    }

    return false;
}

static inline size_t SIToBytes(std::istringstream& iss)
{
    double size;
    std::string units;

    iss >> size;
    if (iss.fail()) {
        // not prefixed by a number
        return 0;
    }

    iss >> units;
    if (iss.fail() && iss.eof()) {
        // no units given; clear fail flag
        // and assume bytes
        iss.clear(std::ios::eofbit);
        return (size_t)ceil(size);
    }

    if (units.size() > 1) {
        // unrecognized multichar suffix
        iss.setstate(std::ios::failbit);
        return 0;
    }

    switch(tolower(units[0])) {
    case 'k':
        size *= (size_t)1<<10;
        break;
    case 'm':
        size *= (size_t)1<<20;
        break;
    case 'g':
        size *= (size_t)1<<30;
        break;
    default:
        iss.setstate(std::ios::failbit);
        return 0;
    }

    return (size_t)ceil(size);
}

static inline size_t SIToBytes(const std::string& str)
{
    std::istringstream iss(str);
    return SIToBytes(iss);
}

#endif

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top