Markdown code blocks migration part 8 (#22478)

This commit is contained in:
Andrey Makarov
2023-08-14 22:27:36 -06:00
committed by GitHub
parent 1927ae72d0
commit a660c17d30
46 changed files with 725 additions and 629 deletions

View File

@@ -163,11 +163,12 @@ when defined(nimdoc):
##
## **Examples:**
##
## .. code-block:: nim
## ```nim
## when declared(paramCount):
## # Use paramCount() here
## else:
## # Do something else!
## ```
proc paramStr*(i: int): string {.tags: [ReadIOEffect].} =
## Returns the `i`-th `command line argument`:idx: given to the application.
@@ -195,11 +196,12 @@ when defined(nimdoc):
##
## **Examples:**
##
## .. code-block:: nim
## ```nim
## when declared(paramStr):
## # Use paramStr() here
## else:
## # Do something else!
## ```
elif defined(nimscript): discard
elif defined(nodejs):
@@ -296,11 +298,12 @@ when declared(paramCount) or defined(nimdoc):
##
## **Examples:**
##
## .. code-block:: nim
## ```nim
## when declared(commandLineParams):
## # Use commandLineParams() here
## else:
## # Do something else!
## ```
result = @[]
for i in 1..paramCount():
result.add(paramStr(i))

View File

@@ -19,7 +19,7 @@ const
# Inspired by https://engineering.fb.com/2013/03/15/developer-tools/three-optimization-tips-for-c
# Generates:
# .. code-block:: nim
# ```nim
# var res = ""
# for i in 0 .. 99:
# if i < 10:
@@ -27,6 +27,7 @@ const
# else:
# res.add $i
# doAssert res == digits100
# ```
proc utoa2Digits*(buf: var openArray[char]; pos: int; digits: uint32) {.inline.} =
buf[pos] = digits100[2 * digits]

View File

@@ -15,19 +15,19 @@ The emulation cannot be 100% faithful and to avoid adding too much complexity,
template since*(version: (int, int), body: untyped) {.dirty.} =
## Evaluates `body` if the ``(NimMajor, NimMinor)`` is greater than
## or equal to `version`. Usage:
##
## .. code-block:: Nim
## ```Nim
## proc fun*() {.since: (1, 3).}
## since (1, 3): fun()
## ```
when (NimMajor, NimMinor) >= version:
body
template since*(version: (int, int, int), body: untyped) {.dirty.} =
## Evaluates `body` if ``(NimMajor, NimMinor, NimPatch)`` is greater than
## or equal to `version`. Usage:
##
## .. code-block:: Nim
## ```Nim
## proc fun*() {.since: (1, 3, 1).}
## since (1, 3, 1): fun()
## ```
when (NimMajor, NimMinor, NimPatch) >= version:
body

View File

@@ -31,37 +31,38 @@
## Examples
## ========
##
## .. code-block:: Nim
## import std/socketstreams
## ```Nim
## import std/socketstreams
##
## var
## socket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
## stream = newReadSocketStream(socket)
## socket.sendTo("127.0.0.1", Port(12345), "SOME REQUEST")
## echo stream.readLine() # Will call `recv`
## stream.setPosition(0)
## echo stream.readLine() # Will return the read line from the buffer
## stream.resetStream() # Buffer is now empty, position is 0
## echo stream.readLine() # Will call `recv` again
## stream.close() # Closes the socket
## var
## socket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
## stream = newReadSocketStream(socket)
## socket.sendTo("127.0.0.1", Port(12345), "SOME REQUEST")
## echo stream.readLine() # Will call `recv`
## stream.setPosition(0)
## echo stream.readLine() # Will return the read line from the buffer
## stream.resetStream() # Buffer is now empty, position is 0
## echo stream.readLine() # Will call `recv` again
## stream.close() # Closes the socket
## ```
##
## .. code-block:: Nim
## ```Nim
## import std/socketstreams
##
## import std/socketstreams
##
## var socket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
## socket.connect("127.0.0.1", Port(12345))
## var sendStream = newWriteSocketStream(socket)
## sendStream.write "NOM"
## sendStream.setPosition(1)
## echo sendStream.peekStr(2) # OM
## sendStream.write "I"
## sendStream.setPosition(0)
## echo sendStream.readStr(3) # NIM
## echo sendStream.getPosition() # 3
## sendStream.flush() # This actually performs the writing to the socket
## sendStream.setPosition(1)
## sendStream.write "I" # Throws an error as we can't write into an already sent buffer
## var socket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
## socket.connect("127.0.0.1", Port(12345))
## var sendStream = newWriteSocketStream(socket)
## sendStream.write "NOM"
## sendStream.setPosition(1)
## echo sendStream.peekStr(2) # OM
## sendStream.write "I"
## sendStream.setPosition(0)
## echo sendStream.readStr(3) # NIM
## echo sendStream.getPosition() # 3
## sendStream.flush() # This actually performs the writing to the socket
## sendStream.setPosition(1)
## sendStream.write "I" # Throws an error as we can't write into an already sent buffer
## ```
import net, streams

View File

@@ -12,27 +12,27 @@
## Examples
## ========
##
## .. code-block:: Nim
## ```Nim
## import std/locks
##
## import std/locks
## var
## thr: array[0..4, Thread[tuple[a,b: int]]]
## L: Lock
##
## var
## thr: array[0..4, Thread[tuple[a,b: int]]]
## L: Lock
## proc threadFunc(interval: tuple[a,b: int]) {.thread.} =
## for i in interval.a..interval.b:
## acquire(L) # lock stdout
## echo i
## release(L)
##
## proc threadFunc(interval: tuple[a,b: int]) {.thread.} =
## for i in interval.a..interval.b:
## acquire(L) # lock stdout
## echo i
## release(L)
## initLock(L)
##
## initLock(L)
## for i in 0..high(thr):
## createThread(thr[i], threadFunc, (i*10, i*10+5))
## joinThreads(thr)
##
## for i in 0..high(thr):
## createThread(thr[i], threadFunc, (i*10, i*10+5))
## joinThreads(thr)
##
## deinitLock(L)
## deinitLock(L)
## ```